C# FileStream.Seek的代码示例
FileStream.Seek方法的主要功能描述
通过代码示例来学习C# FileStream.Seek方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
FileStream.Seek是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的FileStream.Seek() 已经帮大家高亮显示了,大家可以重点学习FileStream.Seek() 方法的写法,从而快速掌握该方法的应用。
FileStream.Seek的代码示例1 - GetEmbeddedData()
using System.IO;
///
/// Extracts the data embedded into MSI (into Binary table).
///
/// The session.
/// The name on resource in the Binary table.
///
public static byte[] GetEmbeddedData(this Session session, string binary)
{
//If binary is accessed this way it will raise "stream handle is not valid" exception
//object result = session.Database.ExecuteScalar("select Data from Binary where Name = 'Fake_CRT.msi'");
//Stream s = (Stream)result;
//using (FileStream fs = new FileStream(@"....\Wix# Samples\Simplified Bootstrapper\Fake CRT1.msi", FileMode.Create))
//{
// int Length = 256;
// var buffer = new Byte[Length];
// int bytesRead = s.Read(buffer, 0, Length);
// while (bytesRead > 0)
// {
// fs.Write(buffer, 0, bytesRead);
// bytesRead = s.Read(buffer, 0, Length);
// }
//}
//however View approach is OK
using (var sql = session.Database.OpenView("select Data from Binary where Name = '" + binary + "'"))
{
sql.Execute();
using (var record = sql.Fetch())
using (var stream = record.GetStream(1))
using (var ms = new IO.MemoryStream())
{
int Length = 256;
var buffer = new Byte[Length];
int bytesRead = stream.Read(buffer, 0, Length);
while (bytesRead > 0)
{
ms.Write(buffer, 0, bytesRead);
bytesRead = stream.Read(buffer, 0, Length);
}
ms.Seek(0, IO.SeekOrigin.Begin);
return ms.ToArray();
}
}
}
开发者ID: oleg-shilo, 项目名称: wixsharp, 代码行数: 47, 代码来源: Extensions.cs
在oleg-shilo提供的GetEmbeddedData()方法中,该源代码示例一共有47行, 其中使用了FileStream.Seek()1次, 并且小编将这些方法高亮显示出来了,希望对您了解FileStream.Seek()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解FileStream.Seek()可能更有帮助。
FileStream.Seek的代码示例2 - AddBoardsToSet()
using System.IO;
public void AddBoardsToSet(List FileList, ProgressLog Logger , bool fixgroup = true, bool forcezerowidth = false)
{
Logger.PushActivity("AddBoardsToSet");
foreach (var a in FileList)
{
Logger.AddString(String.Format("adding {0}", a));
BoardSide aSide = BoardSide.Unknown;
BoardLayer aLayer = BoardLayer.Unknown;
string ext = Path.GetExtension(a);
if (ext == ".zip")
{
using (ZipFile zip1 = ZipFile.Read(a))
{
foreach (ZipEntry e in zip1)
{
MemoryStream MS = new MemoryStream();
if (e.IsDirectory == false)
{
// e.Extract(MS);
// MS.Seek(0, SeekOrigin.Begin);
Gerber.DetermineBoardSideAndLayer(e.FileName, out aSide, out aLayer);
if (aLayer == BoardLayer.Outline) hasgko = true;
// AddFileStream(MS, e.FileName, drillscaler);
}
}
}
}
else
{
Gerber.DetermineBoardSideAndLayer(a, out aSide, out aLayer);
}
if (aLayer == BoardLayer.Outline) hasgko = true;
}
foreach (var a in FileList)
{
if (Logger != null) Logger.AddString(String.Format("Loading {0}", Path.GetFileName(a)));
string ext = Path.GetExtension(a);
if (ext == ".zip")
{
using (ZipFile zip1 = ZipFile.Read(a))
{
foreach (ZipEntry e in zip1)
{
MemoryStream MS = new MemoryStream();
if (e.IsDirectory == false)
{
if (Logger != null) Logger.AddString(String.Format("Loading inside zip: {0}", Path.GetFileName(e.FileName)));
e.Extract(MS);
MS.Seek(0, SeekOrigin.Begin);
AddFileToSet(MS, e.FileName, Logger, 1, forcezerowidth);
}
}
}
}
else
{
try
{
MemoryStream MS2 = new MemoryStream();
FileStream FS = File.OpenRead(a);
FS.CopyTo(MS2);
MS2.Seek(0, SeekOrigin.Begin);
AddFileToSet(MS2, a, Logger,1, forcezerowidth);
}
catch (Exception E)
{
Logger.AddString(String.Format("Failed to add file! {0},{1}", a, E));
}
}
}
if (fixgroup)
{
if (Logger != null) Logger.AddString("Checking for common file format mistakes.");
FixEagleDrillExportIssues(Logger);
CheckRelativeBoundingBoxes(Logger);
CheckForOutlineFiles(Logger);
CheckRelativeBoundingBoxes(Logger);
}
Logger.PopActivity();
}
开发者ID: ThisIsNotRocketScience, 项目名称: GerberTools, 代码行数: 90, 代码来源: ImageCreator.cs
在ThisIsNotRocketScience提供的AddBoardsToSet()方法中,该源代码示例一共有90行, 其中使用了FileStream.Seek()3次, 并且小编将这些方法高亮显示出来了,希望对您了解FileStream.Seek()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解FileStream.Seek()可能更有帮助。
FileStream.Seek的代码示例3 - AddFile()
using System.IO;
public void AddFile(ProgressLog log, string filename, double drillscaler = 1.0)
{
string[] filesplit = filename.Split('.');
string ext = filesplit[filesplit.Count() - 1].ToLower();
if (ext == "zip")
{
using (ZipFile zip1 = ZipFile.Read(filename))
{
foreach (ZipEntry e in zip1)
{
MemoryStream MS = new MemoryStream();
if (e.IsDirectory == false)
{
e.Extract(MS);
MS.Seek(0, SeekOrigin.Begin);
AddFileStream(log, MS, e.FileName, drillscaler);
}
}
}
return;
}
MemoryStream MS2 = new MemoryStream();
FileStream FS = File.OpenRead(filename);
FS.CopyTo(MS2);
MS2.Seek(0, SeekOrigin.Begin);
AddFileStream(log, MS2, filename, drillscaler);
}
开发者ID: ThisIsNotRocketScience, 项目名称: GerberTools, 代码行数: 34, 代码来源: LoadedStuff.cs
在ThisIsNotRocketScience提供的AddFile()方法中,该源代码示例一共有34行, 其中使用了FileStream.Seek()2次, 并且小编将这些方法高亮显示出来了,希望对您了解FileStream.Seek()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解FileStream.Seek()可能更有帮助。
FileStream.Seek的代码示例4 - AddBoardsToSet()
using System.IO;
public void AddBoardsToSet(List FileList, bool fixgroup = true, ProgressLog Logger = null)
{
foreach (var a in FileList)
{
BoardSide aSide = BoardSide.Unknown;
BoardLayer aLayer = BoardLayer.Unknown;
string ext = Path.GetExtension(a);
if (ext == ".zip")
{
using (ZipFile zip1 = ZipFile.Read(a))
{
foreach (ZipEntry e in zip1)
{
MemoryStream MS = new MemoryStream();
if (e.IsDirectory == false)
{
// e.Extract(MS);
// MS.Seek(0, SeekOrigin.Begin);
Gerber.DetermineBoardSideAndLayer(e.FileName, out aSide, out aLayer);
if (aLayer == BoardLayer.Outline) HasLoadedOutline = true;
// AddFileStream(MS, e.FileName, drillscaler);
}
}
}
}
else
{
Gerber.DetermineBoardSideAndLayer(a, out aSide, out aLayer);
}
if (aLayer == BoardLayer.Outline) HasLoadedOutline = true;
}
foreach (var a in FileList)
{
if (Logger != null) Logger.AddString(String.Format("Loading {0}", Path.GetFileName(a)));
string ext = Path.GetExtension(a);
if (ext == ".zip")
{
using (ZipFile zip1 = ZipFile.Read(a))
{
foreach (ZipEntry e in zip1)
{
MemoryStream MS = new MemoryStream();
if (e.IsDirectory == false)
{
if (Logger != null) Logger.AddString(String.Format("Loading inside zip: {0}", Path.GetFileName(e.FileName)));
e.Extract(MS);
MS.Seek(0, SeekOrigin.Begin);
AddFileToSet(MS, e.FileName, Logger);
}
}
}
}
else
{
MemoryStream MS2 = new MemoryStream();
FileStream FS = File.OpenRead(a);
FS.CopyTo(MS2);
MS2.Seek(0, SeekOrigin.Begin);
AddFileToSet(MS2, a, Logger);
}
}
if (fixgroup)
{
if (Logger != null) Logger.AddString("Checking for common file format mistakes.");
FixEagleDrillExportIssues(Logger);
CheckRelativeBoundingBoxes(Logger);
CheckForOutlineFiles(Logger);
CheckRelativeBoundingBoxes(Logger);
}
}
开发者ID: ThisIsNotRocketScience, 项目名称: GerberTools, 代码行数: 79, 代码来源: SickOfBeige.cs
在ThisIsNotRocketScience提供的AddBoardsToSet()方法中,该源代码示例一共有79行, 其中使用了FileStream.Seek()3次, 并且小编将这些方法高亮显示出来了,希望对您了解FileStream.Seek()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解FileStream.Seek()可能更有帮助。
FileStream.Seek的代码示例5 - GetBeaconsFromFile()
using System.IO;
///
/// Get Cobalt Strike Configurations from a file and output their contents to the console .
///
/// Name of memory/dump file to be scanned for Cobalt Strike beacons
private static void GetBeaconsFromFile(string fileName)
{
OutputMessageToConsole(LogLevel.Info, $"Scanning file: {fileName}");
List beacons = new List();
if (File.Exists(fileName))
{
// Check the size of the file. If > 500MB, and notify that scanning will take time
var fileSize = new FileInfo(fileName).Length;
if (fileSize > Int32.MaxValue)
{
OutputMessageToConsole(LogLevel.Warn, $"\tFile is large: {fileSize / (1024 * 1024)} MB. Scanning will be slow.");
}
// Yara scan the file and return any matches
List beaconMatches = CobaltStrikeScan.YaraScanFile(fileName, opts.Verbose);
// Extract config bytes at each match offset and parse the beacon config from them
if (beaconMatches.Count > 0)
{
if (opts.Verbose)
{
OutputMessageToConsole(LogLevel.Info, $"\t{beaconMatches.Count} Signature(s) detected in file. Attempting to extract and parse config...\n");
}
foreach (BeaconMatch match in beaconMatches)
{
try
{
byte[] beaconConfigBytes = new byte[4096];
// Get a byte array from the offset of the file with beacon matches to avoid cases
// where the file is too big to read in to a File object
using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
fileStream.Seek((long)match.Offset, SeekOrigin.Begin);
fileStream.Read(beaconConfigBytes, 0, 4096);
}
match.Offset = 0;
beacons.Add(new Beacon(beaconConfigBytes, match.Offset, match.Version));
}
catch (System.IO.IOException)
{
/*
if (opts.Verbose)
{
OutputMessageToConsole(LogLevel.Error, $"Error extracting signatured data from file at offset: {match.Offset}");
}
*/
}
}
if (beacons.Count > 0)
{
foreach (Beacon beacon in beacons)
{
if (beacon.isValidBeacon())
{
OutputMessageToConsole(LogLevel.Success, $"Cobalt Strike Beacon Configuration\n");
beacon.OutputToConsole();
}
}
}
else
OutputBeaconNotFoundMessage();
}
else { OutputBeaconNotFoundMessage(); }
}
else
{
OutputMessageToConsole(LogLevel.Error, $"File doesn't exist: {fileName}\nExiting...");
System.Environment.Exit(1);
}
}
开发者ID: Apr4h, 项目名称: CobaltStrikeScan, 代码行数: 78, 代码来源: ConsoleUI.cs
在Apr4h提供的GetBeaconsFromFile()方法中,该源代码示例一共有78行, 其中使用了FileStream.Seek()1次, 并且小编将这些方法高亮显示出来了,希望对您了解FileStream.Seek()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解FileStream.Seek()可能更有帮助。
FileStream.Seek的代码示例6 - WriteFile()
using System.IO;
//Saving memory stream to a new file with the given path
private static bool WriteFile(MemoryStream InputStream, string path)
{
if (File.Exists(path))
File.Delete(path);
if (!File.Exists(path))
{
try
{
using (FileStream fs = File.Create(path))
{
InputStream.Seek(0, SeekOrigin.Begin);
InputStream.CopyTo(fs);
}
return true;
}
catch (Exception e)
{
Console.WriteLine("The following exception was thrown during creation and writing to the file \"{0}\"", path);
Console.WriteLine(e.Message);
return false;
}
}
else
{
Console.WriteLine("Can not create file \"{0}\". File already exists", path);
return false;
}
}
开发者ID: Cinchoo, 项目名称: ChoETL, 代码行数: 33, 代码来源: Program.cs
在Cinchoo提供的WriteFile()方法中,该源代码示例一共有33行, 其中使用了FileStream.Seek()1次, 并且小编将这些方法高亮显示出来了,希望对您了解FileStream.Seek()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解FileStream.Seek()可能更有帮助。
FileStream.Seek()方法的常见问题及解答
C#中FileStream.Seek()的常见错误类型及注意事项
FileStream.Seek的错误类型有很多, 这里就不一一阐述了,本文只列出一些常见的代码示例供参考,大家可以看一下代码中Catch语句中是否有常见的错误捕获及处理。
C#中FileStream.Seek()的构造函数有哪些
FileStream.Seek构造函数功能基本类似,只是参数不同; 目前主流的集成开发环境都已经带智能提醒了,如:Visual Studio; 大家可以非常轻松的通过Visual Studio中的智能提醒,了解对应构造函数的用法。
如何使用ChartGPT写一段FileStream.Seek的代码
你可以在ChartGPT中输入如下的指令:"提供一个如何使用FileStream.Seek的C#代码示例"
ChartGPT写出的代码和本文中的小编提供的代码的区别。 ChartGPT发展到现在已经非常聪明了,但需要使用这提供非常专业的问题,才可能有比较好的源代码示例; 而本文中, 小编已经帮您列出来基本所有类和所有方法的使用示例, 而且这些示例基本都是一些网络大佬提供的源码,可以更方便的供一些开发菜鸟或者资深开发参考和学习。
FileStream.Seek所在的类及名称空间
FileStream.Seek是System.IO下的方法。
FileStream.Seek怎么使用?
FileStream.Seek使用上比较简单,可以参考MSDN中的帮助文档,也参考本文中提供的7个使用示例。
FileStream.Seek菜鸟教程
对于菜鸟来说,本文中提供的7个FileStream.Seek写法都将非常直观的帮您掌握FileStream.Seek的用法,是一个不错的参考教程。
本文中的FileStream.Seek方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。