當前位置: 首頁>>代碼示例>>C#>>正文


C# IO.File類代碼示例

本文整理匯總了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");
            }
        }
開發者ID:AnotherAltr,項目名稱:Rc.Core,代碼行數:25,代碼來源:MetadataPartition.cs

示例2: Reader

 public Reader(File file)
 {
     _file = file;
     _totalSize = file.GetSize();
     _ofs = 0;
     FillBuffer();
 }
開發者ID:Bobris,項目名稱:BTDB,代碼行數:7,代碼來源:InMemoryFileCollection.cs

示例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);
              }
        }
開發者ID:blinkseb,項目名稱:FMS,代碼行數:32,代碼來源:DiskStructure.cs

示例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");
        }
開發者ID:ridhouan,項目名稱:teamlab.v6.5,代碼行數:31,代碼來源:ProviderFileDao.cs

示例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;
		  }
		}
	  }
開發者ID:WakeflyCBass,項目名稱:lucenenet,代碼行數:34,代碼來源:MappingCharFilterFactory.cs

示例6: Save

 public static void Save(File file)
 {
     using (var istorage = IsolatedStorageFile.GetUserStoreForApplication())
     {
         WriteFileToFile(file, istorage, GetFilePath(file));
     }
 }
開發者ID:halllo,項目名稱:SilverlightRun,代碼行數:7,代碼來源:IsolatedFiles.cs

示例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;
            }
        }
開發者ID:NikitoG,項目名稱:TelerikAcademyHomeworks,代碼行數:29,代碼來源:Startup.cs

示例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();
     }
 }
開發者ID:srushti,項目名稱:azazel,代碼行數:29,代碼來源:IconExtractor.cs

示例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;
        }
開發者ID:vadimsu,項目名稱:PACK,代碼行數:42,代碼來源:ChunksFiles.cs

示例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;
        }
開發者ID:ridhouan,項目名稱:teamlab.v6.5,代碼行數:35,代碼來源:SharpBoxFileDao.cs

示例11: TemporaryLocalFile

        public TemporaryLocalFile(File backingFile)
        {
            _backingFile = backingFile;

            if (!backingFile.Exists())
                backingFile.Create();
        }
開發者ID:DotNetIO,項目名稱:DotNetIO,代碼行數:7,代碼來源:TemporaryLocalFile.cs

示例12: CopyFileAction

 public CopyFileAction(File source, Storage destinationStorage, string destinationPath, string destinationName)
 {
     Source = source;
     DestinationStorage = destinationStorage;
     DestinationPath = destinationPath;
     DestinationName = destinationName;
 }
開發者ID:jbatonnet,項目名稱:smartsync,代碼行數:7,代碼來源:CopyFile.cs

示例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));
        }
開發者ID:rprieto,項目名稱:EpisodeWizard,代碼行數:8,代碼來源:Keywords.cs

示例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);
 }
開發者ID:srushti,項目名稱:azazel,代碼行數:8,代碼來源:IconExtractor.cs

示例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));
        }
開發者ID:jdeering,項目名稱:SymSharp,代碼行數:8,代碼來源:FileHandlingTests.cs


注:本文中的System.IO.File類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。