本文整理汇总了C#中File类的典型用法代码示例。如果您正苦于以下问题:C# File类的具体用法?C# File怎么用?C# File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
File类属于命名空间,在下文中一共展示了File类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IndexingVariantContextWriter
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Requires({"name != null", "! ( location == null && output == null )", "! ( enableOnTheFlyIndexing && location == null )"}) protected IndexingVariantContextWriter(final String name, final File location, final OutputStream output, final net.sf.samtools.SAMSequenceDictionary refDict, final boolean enableOnTheFlyIndexing)
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
protected internal IndexingVariantContextWriter(string name, File location, OutputStream output, SAMSequenceDictionary refDict, bool enableOnTheFlyIndexing)
{
outputStream = output;
this.name = name;
this.refDict = refDict;
if (enableOnTheFlyIndexing)
{
try
{
idxStream = new LittleEndianOutputStream(new FileOutputStream(Tribble.indexFile(location)));
//System.out.println("Creating index on the fly for " + location);
indexer = new DynamicIndexCreator(IndexFactory.IndexBalanceApproach.FOR_SEEK_TIME);
indexer.initialize(location, indexer.defaultBinSize());
positionalOutputStream = new PositionalOutputStream(output);
outputStream = positionalOutputStream;
}
catch (IOException ex)
{
// No matter what we keep going, since we don't care if we can't create the index file
idxStream = null;
indexer = null;
positionalOutputStream = null;
}
}
}
示例2: Update
public void Update(int id, File entity)
{
var existing = GetById(id);
existing.FileName = entity.FileName;
existing.FilePurpose = entity.FilePurpose;
}
示例3: InsertFile
public static File InsertFile(DriveService service, string mimeType, string filename, System.IO.Stream stream)
{
// File's metadata.
File body = new File();
body.Title = filename;
body.MimeType = mimeType;
body.Parents = new List<ParentReference>() { new ParentReference() { Id = "0BySX8GhV2wf8enhxSU56N25Rbnc" } };
try
{
FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, mimeType);
request.Upload();
File file = request.ResponseBody;
// Uncomment the following line to print the File ID.
// Console.WriteLine("File ID: " + file.Id);
return file;
}
catch (Exception e)
{
Console.WriteLine("An error occurred: " + e.Message);
return null;
}
}
示例4: Index
public Index(File file, string name, BiosParameterBlock bpb, UpperCase upCase)
{
_file = file;
_name = name;
_bpb = bpb;
_isFileIndex = name == "$I30";
_blockCache = new ObjectCache<long, IndexBlock>();
_root = _file.GetStream(AttributeType.IndexRoot, _name).GetContent<IndexRoot>();
_comparer = _root.GetCollator(upCase);
using (Stream s = _file.OpenStream(AttributeType.IndexRoot, _name, FileAccess.Read))
{
byte[] buffer = Utilities.ReadFully(s, (int)s.Length);
_rootNode = new IndexNode(WriteRootNodeToDisk, 0, this, true, buffer, IndexRoot.HeaderOffset);
// Give the attribute some room to breathe, so long as it doesn't squeeze others out
// BROKEN, BROKEN, BROKEN - how to figure this out? Query at the point of adding entries to the root node?
_rootNode.TotalSpaceAvailable += _file.MftRecordFreeSpace(AttributeType.IndexRoot, _name) - 100;
}
if (_file.StreamExists(AttributeType.IndexAllocation, _name))
{
_indexStream = _file.OpenStream(AttributeType.IndexAllocation, _name, FileAccess.ReadWrite);
}
if (_file.StreamExists(AttributeType.Bitmap, _name))
{
_indexBitmap = new Bitmap(_file.OpenStream(AttributeType.Bitmap, _name, FileAccess.ReadWrite), long.MaxValue);
}
}
示例5: debugMode
public void debugMode()
{
//初始化全局块组
for (int i = 0; i < Config.GROUPS; i++)
VFS.BLOCK_GROUPS[i] = new BlockGroup(i);
//初始化目录树
VFS.rootDir = new Directory("/", null);
Directory bootDir = new Directory("boot", VFS.rootDir);
Directory etcDir = new Directory("etc", VFS.rootDir);
Directory libDir = new Directory("lib", VFS.rootDir);
Directory homeDir = new Directory("home", VFS.rootDir);
Directory rootDir = new Directory("root", VFS.rootDir);
Directory tempDir = new Directory("temp", VFS.rootDir);
VFS.rootDir.add(bootDir);
VFS.rootDir.add(etcDir);
VFS.rootDir.add(homeDir);
VFS.rootDir.add(libDir);
VFS.rootDir.add(rootDir);
VFS.rootDir.add(tempDir);
File file1 = new File("bashrc", etcDir);
File file2 = new File("shadowsocks", etcDir);
etcDir.add(file1);
etcDir.add(file2);
}
示例6: RecurseDataSet
public static void RecurseDataSet(File f, DataSet ds, string indent)
{
CSharpDataSet cds = new CSharpDataSet(ds);
while(!cds.IsAtEnd())
{
DataElement de = cds.GetCurrent();
// Compute VR from the toplevel file, and the currently processed dataset:
VR vr = DataSetHelper.ComputeVR(f, ds, de.GetTag() );
if( vr.Compatible( new VR(VR.VRType.SQ) ) )
{
uint uvl = (uint)de.GetVL(); // Test cast is ok
System.Console.WriteLine( indent + de.GetTag().toString() + ":" + uvl ); // why not ?
//SequenceOfItems sq = de.GetSequenceOfItems();
// GetValueAsSQ handle more cases than GetSequenceOfItems
SmartPtrSQ sq = de.GetValueAsSQ();
uint n = sq.GetNumberOfItems();
for( uint i = 1; i <= n; i++) // item starts at 1, not 0
{
Item item = sq.GetItem( i );
DataSet nested = item.GetNestedDataSet();
RecurseDataSet( f, nested, indent + " " );
}
}
else
{
System.Console.WriteLine( indent + de.toString() );
}
cds.Next();
}
}
示例7: TraverseAllFilesAndFolders
private static void TraverseAllFilesAndFolders(string curDirPath, Folder curFolder)
{
try
{
// add all files to curFolder
foreach (var fileName in Directory.GetFiles(curDirPath))
{
ulong fileSize = (ulong) (new FileInfo(fileName).Length);
File fileToAdd = new File(fileName, fileSize);
curFolder.AddFile(fileToAdd);
}
// add all folders to curFolder
foreach (var dirName in Directory.GetDirectories(curDirPath))
{
curFolder.AddFolder(new Folder(dirName));
// take the last folder in the current folder and go through the algorithm again
TraverseAllFilesAndFolders(dirName, curFolder.ChildFolders[curFolder.ChildFolders.Length - 1]);
}
}
catch (UnauthorizedAccessException ex)
{
Console.WriteLine(ex.Message);
}
}
示例8: runServer
public void runServer()
{
tcpListener.Start();
//Byte[] bytes = new Byte[16];
//Byte[] data = new Byte[16];
while (true)
{
TcpClient tcpClient = tcpListener.AcceptTcpClient();
NetworkStream stream = tcpClient.GetStream();
string command = new StreamReader(stream).ReadToEnd();
string[] commands = command.Split(seperators);
if (commands[0].Contains("GET"))
{
file = new File(commands[1]);
FileStream fs = new FileStream(commands[1], FileMode.Open);
int currentPos = 0;
while (currentPos < fs.Length)
{
byte[] bytes = new byte[16];
int data = fs.Read(bytes, currentPos, 16);
stream.Write(bytes, 0, 16);
currentPos += 16;
}
}
}
}
示例9: VCFWriter
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
//ORIGINAL LINE: public VCFWriter(final File location, final OutputStream output, final net.sf.samtools.SAMSequenceDictionary refDict, final boolean enableOnTheFlyIndexing, boolean doNotWriteGenotypes, final boolean allowMissingFieldsInHeader)
public VCFWriter(File location, OutputStream output, SAMSequenceDictionary refDict, bool enableOnTheFlyIndexing, bool doNotWriteGenotypes, bool allowMissingFieldsInHeader) : base(writerName(location, output), location, output, refDict, enableOnTheFlyIndexing)
{
this.doNotWriteGenotypes = doNotWriteGenotypes;
this.allowMissingFieldsInHeader = allowMissingFieldsInHeader;
this.charset = Charset.forName("ISO-8859-1");
this.writer = new OutputStreamWriter(lineBuffer, charset);
}
示例10: ClusterBitmap
public ClusterBitmap(File file)
{
_file = file;
_bitmap = new Bitmap(
_file.OpenStream(AttributeType.Data, null, FileAccess.ReadWrite),
Utilities.Ceil(file.Context.BiosParameterBlock.TotalSectors64, file.Context.BiosParameterBlock.SectorsPerCluster));
}
示例11: Mp3Tag
private string year; // 4
#endregion Fields
#region Constructors
public Mp3Tag(File Music)
{
FileStream fs = System.IO.File.OpenRead(Music.Address());
if (fs.Length >= 128)
{
byte[] btID = new byte[3];
byte[] btTitle = new byte[30];
byte[] btArtist = new byte[30];
byte[] btAlbum = new byte[30];
byte[] btYear = new byte[4];
byte[] btComment = new byte[30];
byte[] btGenre = new byte[1];
fs.Seek(-128, SeekOrigin.End);
fs.Read(btID, 0, 3);
fs.Read(btTitle, 0, 30);
fs.Read(btArtist, 0, 30);
fs.Read(btAlbum, 0, 30);
fs.Read(btYear, 0, 4);
fs.Read(btComment, 0, 30);
fs.Read(btGenre, 0, 1);
id = Encoding.Default.GetString(btID);
if (id.Equals("TAG"))
{
title = Encoding.Default.GetString(btTitle);
artist = Encoding.Default.GetString(btArtist);
album = Encoding.Default.GetString(btAlbum);
year = Encoding.Default.GetString(btYear);
comment = Encoding.Default.GetString(btComment);
genre = Encoding.Default.GetString(btGenre);
}
fs.Close();
}
}
示例12: SaveXml
public bool SaveXml(string path, string indentation = "\t")
{
using (var file = new File(Context, path, FileMode.Write))
{
return SaveXml(file, indentation);
}
}
示例13: LoadXml
public bool LoadXml(string path)
{
using (var file = new File(Context, path, FileMode.Read))
{
return LoadXml(file);
}
}
示例14: ExtractText
public static void ExtractText(File obj)
{
var blob = obj.Blob;
if (blob != null)
{
var txt = _textExtractor.GetText(obj.Blob.GetStream(), blob.MimeType);
var excerpt = obj.Excerpt;
if (string.IsNullOrWhiteSpace(txt))
{
if (excerpt != null)
{
// no excerpt -> delete excerpt object
obj.Context.Delete(excerpt);
}
}
else
{
if (excerpt == null)
{
excerpt = obj.Excerpt = obj.Context.Create<Excerpt>();
excerpt.File = obj;
}
excerpt.Text = txt.Trim();
}
}
}
示例15: OnCreate
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Bundle bundle = (savedInstanceState ?? Intent.Extras);
_requestId = bundle.GetInt(ExtraRequestId, 0);
_mediaAction = bundle.GetString(ExtraMediaAction);
_mediaType = bundle.GetString(ExtraMediaType);
_photoSubDir = bundle.GetString(ExtraPhotosDir);
// see if already presented (in case rotation tore down this intermediate activity)
_presented = bundle.GetBoolean(PresentedBundleKey);
if (!_presented && _mediaAction == SelectMediaAction && _mediaType == PhotoMediaType)
StartPickPhotoIntent();
else if (_mediaAction == CreateMediaAction && _mediaType == PhotoMediaType)
{
if (!_presented)
{
CreatePhotoDir();
if (_dir == null)
{
OnMediaPicked(new MediaPickedEventArgs(_requestId, new System.IO.IOException("Unable to create photo directory.")));
Finish();
return;
}
StartTakePhotoIntent();
}
else
{
var path = bundle.GetString(FilePathKey);
_file = new File(path);
}
}
}