• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IO.File类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.IO.File的典型用法代码示例。如果您正苦于以下问题:C# File类的具体用法?C# File怎么用?C# File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



File类属于System.IO命名空间,在下文中一共展示了File类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: Reader

 public Reader(File owner)
 {
     _owner = owner;
     _valueSize = _owner.GetSize();
     _ofs = 0;
     Buf = new byte[32768];
     FillBuffer();
 }
开发者ID:mano-cz,项目名称:BTDB,代码行数:8,代码来源:OnDiskFileCollection.cs


示例17: Delete

 public static void Delete(File file)
 {
     using (var istorage = IsolatedStorageFile.GetUserStoreForApplication())
     {
         if (istorage.FileExists(file.FileName))
             istorage.DeleteFile(file.FileName);
     }
 }
开发者ID:halllo,项目名称:SilverlightRun,代码行数:8,代码来源:IsolatedFiles.cs


示例18: NotifySpeeder

        public void NotifySpeeder(int cameralocation, double speed, File image)
        {
            //Send to database
            dman.submitToDatabase(cameralocation, speed);

            //Send to car
            Car c = cars.OrderBy(x => x.Location - cameralocation).First();
            c.speeder(cameralocation, speed, image);
        }
开发者ID:nano2nd2,项目名称:SpeederTracker,代码行数:9,代码来源:Dispatcher.cs


示例19: WritePage

 void WritePage(string filename, File.Font f)
 {
     string nfilename = Path.ChangeExtension(filename, ".png"); // we just have one
     f.Frame.Image.Save(nfilename); // just in case -png was not set
     sw.Write("page ");
     sw.Write("id", 0);
     sw.Write("file", nfilename);
     sw.WriteLine();
 }
开发者ID:WarlockD,项目名称:GMdsam,代码行数:9,代码来源:BMFontWriter.cs


示例20: FileCheck_CommandHasWarning_ThrowsFileNotFoundException

        public void FileCheck_CommandHasWarning_ThrowsFileNotFoundException()
        {
            var mockSocket = Substitute.For<ISymSocket>();
            mockSocket.ReadCommand()
                      .Returns(new SymCommand("Check", new Dictionary<string, string> {{"Warning", ""}}));

            var file = new File("symitar", "10", "FILE.TO.CHECK", FileType.RepGen, DateTime.Now, 110);
            var session = new SymSession(mockSocket, 10);
            Assert.Throws<FileNotFoundException>(() => session.FileCheck(file));
        }
开发者ID:jdeering,项目名称:SymSharp,代码行数:10,代码来源:FileHandlingTests.cs



注:本文中的System.IO.File类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IO.FileInfo类代码示例发布时间:2022-05-26
下一篇:
C# IO.ErrorEventArgs类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap