本文整理汇总了C#中System.IO.File类的典型用法代码示例。如果您正苦于以下问题:C# File类的具体用法?C# File怎么用?C# File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
File类属于System.IO命名空间,在下文中一共展示了File类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MetadataPartition
public MetadataPartition(UdfContext context, LogicalVolumeDescriptor volumeDescriptor, MetadataPartitionMap partitionMap)
: base(context, volumeDescriptor)
{
_partitionMap = partitionMap;
PhysicalPartition physical = context.PhysicalPartitions[partitionMap.PartitionNumber];
long fileEntryPos = partitionMap.MetadataFileLocation * (long)volumeDescriptor.LogicalBlockSize;
byte[] entryData = Utilities.ReadFully(physical.Content, fileEntryPos, _context.PhysicalSectorSize);
if (!DescriptorTag.IsValid(entryData, 0))
{
throw new IOException("Invalid descriptor tag looking for Metadata file entry");
}
DescriptorTag dt = Utilities.ToStruct<DescriptorTag>(entryData, 0);
if (dt.TagIdentifier == TagIdentifier.ExtendedFileEntry)
{
ExtendedFileEntry efe = Utilities.ToStruct<ExtendedFileEntry>(entryData, 0);
_metadataFile = new File(context, physical, efe, _volumeDescriptor.LogicalBlockSize);
}
else
{
throw new NotImplementedException("Only EFE implemented for Metadata file entry");
}
}
示例2: Reader
public Reader(File file)
{
_file = file;
_totalSize = file.GetSize();
_ofs = 0;
FillBuffer();
}
示例3: ReadDirectoryStructure
private void ReadDirectoryStructure(Directory rootDirectory)
{
List<File> files = new List<File>();
foreach (var f in rootDirectory.infos.EnumerateFiles())
{
File file = new File(f);
try
{
file.file = TagLib.File.Create(file.infos.FullName);
if (file.file is TagLib.Image.File)
file.file = null;
}
catch (TagLib.UnsupportedFormatException)
{
file.file = null;
}
files.Add(file);
}
List<Directory> directories = new List<Directory>();
foreach (var f in rootDirectory.infos.EnumerateDirectories())
directories.Add(new Directory(f));
rootDirectory.files = files;
rootDirectory.directories = directories;
foreach (var directory in directories)
{
ReadDirectoryStructure(directory);
}
}
示例4: SaveFile
public File SaveFile(File file, Stream fileStream)
{
if (file == null) throw new ArgumentNullException("file");
var fileId = file.ID;
var folderId = file.FolderID;
IDaoSelector selector;
File fileSaved = null;
//Convert
if (fileId != null)
{
selector = GetSelector(fileId);
file.ID = selector.ConvertId(fileId);
if (folderId != null)
file.FolderID = selector.ConvertId(folderId);
fileSaved = selector.GetFileDao(fileId).SaveFile(file, fileStream);
}
else if (folderId != null)
{
selector = GetSelector(folderId);
file.FolderID = selector.ConvertId(folderId);
fileSaved = selector.GetFileDao(folderId).SaveFile(file, fileStream);
}
if (fileSaved != null)
{
return fileSaved;
}
throw new ArgumentException("No file id or folder id toFolderId determine provider");
}
示例5: inform
// TODO: this should use inputstreams from the loader, not File!
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public void inform(org.apache.lucene.analysis.util.ResourceLoader loader) throws java.io.IOException
public virtual void inform(ResourceLoader loader)
{
if (mapping != null)
{
IList<string> wlist = null;
File mappingFile = new File(mapping);
if (mappingFile.exists())
{
wlist = getLines(loader, mapping);
}
else
{
IList<string> files = splitFileNames(mapping);
wlist = new List<>();
foreach (string file in files)
{
IList<string> lines = getLines(loader, file.Trim());
wlist.AddRange(lines);
}
}
NormalizeCharMap.Builder builder = new NormalizeCharMap.Builder();
parseRules(wlist, builder);
normMap = builder.build();
if (normMap.map == null)
{
// if the inner FST is null, it means it accepts nothing (e.g. the file is empty)
// so just set the whole map to null
normMap = null;
}
}
}
示例6: Save
public static void Save(File file)
{
using (var istorage = IsolatedStorageFile.GetUserStoreForApplication())
{
WriteFileToFile(file, istorage, GetFilePath(file));
}
}
示例7: GetAllFilesAndFoldersInGivenDirectory
private static void GetAllFilesAndFoldersInGivenDirectory(DirectoryInfo directory, Folder folder)
{
try
{
var files = directory.GetFiles();
foreach (var file in files)
{
var myFile = new File();
myFile.Name = file.Name;
myFile.Size = file.Length;
folder.Files.Add(myFile);
}
var directories = directory.GetDirectories();
foreach (var dir in directories)
{
var newFolder = new Folder(dir.Name);
GetAllFilesAndFoldersInGivenDirectory(dir, newFolder);
folder.ChildFolder.Add(newFolder);
}
}
catch (UnauthorizedAccessException)
{
return;
}
}
示例8: Extract
public ImageSource Extract(File file)
{
try {
if (new List<string> {".ico", ".png", ".jpg", ".gif"}.Contains(file.Extension.ToLower())) {
if (!file.Exists()) return new BitmapImage();
return new BitmapImage(new Uri(file.FullName));
}
Icon icon = ExtractIcon(ActualFile(file));
Bitmap bmp = icon.ToBitmap();
DestroyIcon(icon.Handle);
var strm = new MemoryStream();
bmp.Save(strm, ImageFormat.Png);
return Extract(strm);
}
catch (ExternalException exception) {
LogManager.WriteLog(exception);
return new BitmapImage();
}
catch (DirectoryNotFoundException exception) {
LogManager.WriteLog("Requested file: {0}", file);
LogManager.WriteLog(exception);
return new BitmapImage();
}
catch (ArgumentException exception) {
LogManager.WriteLog("Requested file: {0}", file);
LogManager.WriteLog(exception);
return new BitmapImage();
}
}
示例9: addFile
/**
*
* @param file
* File object.
* @param chunkList
* Chunk list, maybe with duplicates.
* @return Number of new chunks, that were not in the list before. Duplicates within the file are considered only
* once.
*/
public int addFile(File file, List<long> chunkList)
{
// Sanity check
if (file == null || chunkList == null || (chunkList.Count == 0))
return 0;
int result = 0;
long offset = 0;
// Walk through the chunks
foreach (long curChunk in chunkList)
{
HashSet<FileAndOffset> files;
files = null;
chunksFiles.TryGetValue(curChunk, out files);
if (files == null)
{
// Create a new file list for the current chunk
files = new HashSet<FileAndOffset>();
chunksFiles.Add(curChunk, files);
// Indicate that the current chunk is new to this list
result++;
}
// Add the file to the file list for the current chunk
files.Add(new FileAndOffset(file, offset));
offset += StreamChunckingLib.PackChunking.chunkToLen(curChunk);
}
return result;
}
示例10: SaveFile
public File SaveFile(File file, Stream fileStream)
{
if (fileStream == null) throw new ArgumentNullException("fileStream");
ICloudFileSystemEntry entry = null;
if(file.ID != null)
{
entry = SharpBoxProviderInfo.Storage.GetFile(MakePath(file.ID), null);
}
else if (file.FolderID != null)
{
var folder = GetFolderById(file.FolderID);
try
{
//Check existense
if (SharpBoxProviderInfo.Storage.GetFileSystemObject(file.Title, folder) != null)
throw new ArgumentException(string.Format(Web.Files.Resources.FilesCommonResource.Error_FileAlreadyExists, file.Title));
}
catch(ArgumentException)
{
throw;
}
catch (Exception)
{
}
entry = SharpBoxProviderInfo.Storage.CreateFile(folder, file.Title);
}
if (entry != null)
{
entry.GetDataTransferAccessor().Transfer(fileStream, nTransferDirection.nUpload);
return ToFile(entry);
}
return null;
}
示例11: TemporaryLocalFile
public TemporaryLocalFile(File backingFile)
{
_backingFile = backingFile;
if (!backingFile.Exists())
backingFile.Create();
}
示例12: CopyFileAction
public CopyFileAction(File source, Storage destinationStorage, string destinationPath, string destinationName)
{
Source = source;
DestinationStorage = destinationStorage;
DestinationPath = destinationPath;
DestinationName = destinationName;
}
示例13: Keywords
public Keywords(File file)
{
this.List = new WeightedGuessList<FuzzyString>();
var cleanPath = RemoveNoise(file.Path.ToLower());
ExtractKeywordsFromPath(Path.GetDirectoryName(cleanPath));
ExtractInfoFromName(Path.GetFileNameWithoutExtension(cleanPath));
}
示例14: ActualFile
private static File ActualFile(File file)
{
if (!file.FullName.EndsWith(".lnk")) return file;
string linkPathName = file.FullName;
var link = (IWshShortcut) new WshShell().CreateShortcut(linkPathName);
if (string.IsNullOrEmpty(link.TargetPath) || !File.Exists(link.TargetPath)) return file;
return new File(link.TargetPath);
}
示例15: FileCheck_LetterFile_ThrowsException
public void FileCheck_LetterFile_ThrowsException()
{
var mockSocket = Substitute.For<ISymSocket>();
var file = new File("symitar", "10", "FILE.TO.CHECK", FileType.Letter, DateTime.Now, 110);
var session = new SymSession(mockSocket, 10);
Assert.Throws<Exception>(() => session.FileCheck(file));
}