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

C# File类代码示例

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

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



File类属于命名空间,在下文中一共展示了File类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
				}
			}
		}
开发者ID:w3he,项目名称:Bio.VCF,代码行数:29,代码来源:IndexingVariantContextWriter.cs


示例2: Update

        public void Update(int id, File entity)
        {
            var existing = GetById(id);

            existing.FileName = entity.FileName;
            existing.FilePurpose = entity.FilePurpose;
        }
开发者ID:hmnzr,项目名称:PSAEC-Website,代码行数:7,代码来源:FilesRepository.cs


示例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;
            }
        }
开发者ID:KristianKirov,项目名称:CinguettioDataService,代码行数:25,代码来源:DriveServiceInvoker.cs


示例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);
            }
        }
开发者ID:alexcmd,项目名称:DiscUtils,代码行数:32,代码来源:Index.cs


示例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);
        }
开发者ID:RainsSoft,项目名称:VFS-2,代码行数:27,代码来源:Form1.cs


示例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();
      }
    }
开发者ID:chris-ondemand3d,项目名称:GDCM,代码行数:31,代码来源:SimplePrint.cs


示例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);
            }
        }
开发者ID:jesusico83,项目名称:Telerik,代码行数:27,代码来源:FilesAndFoldersAsTree.cs


示例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;
                    }
                }
            }
        }
开发者ID:j0z,项目名称:Alexandria,代码行数:33,代码来源:Server.cs


示例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);
		}
开发者ID:w3he,项目名称:Bio.VCF,代码行数:9,代码来源:VCFWriter.cs


示例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));
 }
开发者ID:JGTM2016,项目名称:discutils,代码行数:7,代码来源:ClusterBitmap.cs


示例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();
            }
        }
开发者ID:KostikDodik,项目名称:MediaXplore,代码行数:40,代码来源:Tag.cs


示例12: SaveXml

		public bool SaveXml(string path, string indentation = "\t")
		{
			using (var file = new File(Context, path, FileMode.Write))
			{
				return SaveXml(file, indentation);
			}
		}
开发者ID:corefan,项目名称:urho,代码行数:7,代码来源:Scene.cs


示例13: LoadXml

		public bool LoadXml(string path)
		{
			using (var file = new File(Context, path, FileMode.Read))
			{
				return LoadXml(file);
			}
		}
开发者ID:corefan,项目名称:urho,代码行数:7,代码来源:Scene.cs


示例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();
                }
            }
        }
开发者ID:daszat,项目名称:zetbox,代码行数:27,代码来源:FileActions.cs


示例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);
                }
            }
        }
开发者ID:JC-Chris,项目名称:XFExtensions,代码行数:35,代码来源:MetaMediaActivity.cs


示例16: Play

        public void Play(string filePath)
        {
            try
            {
                if (player == null)
                {
                    player = new MediaPlayer();
                }
                else
                {
                    player.Reset();
                }

                // This method works better than setting the file path in SetDataSource. Don't know why.
                var file = new File(filePath);
                var fis = new FileInputStream(file);

                player.SetDataSource(fis.FD);

                //player.SetDataSource(filePath);
                player.Prepare();
                player.Start();
            }
            catch (Exception ex)
            {
                System.Console.Out.WriteLine(ex.StackTrace);
            }
        }
开发者ID:shawancyb,项目名称:VoiceTimeCounter,代码行数:28,代码来源:AudioPlayer.cs


示例17: TraverseFolders

        public static Folder TraverseFolders(string path, ref Folder myFolder)
        {
            //DirectoryInfo di = new DirectoryInfo(path);
            //Folder myFolder = new Folder(di.Name);
            var subFolders = Directory.GetDirectories(path);

            var files = Directory.GetFiles(path);
            foreach (var file in files)
            {
                FileInfo fi = new FileInfo(file);
                File fileToAdd = new File(fi.Name, fi.Length);
                myFolder.AddFile(fileToAdd);
            }

            foreach (var subFolder in subFolders)
            {
                DirectoryInfo dir = new DirectoryInfo(subFolder);
                Folder folderToAdd = new Folder(dir.Name);
                myFolder.AddFolder(folderToAdd);

                TraverseFolders(subFolder, ref folderToAdd);
            }

            return myFolder;
        }
开发者ID:abaditsegay,项目名称:SVN,代码行数:25,代码来源:Program.cs


示例18: updateFile

        /// <summary>
        /// Updates a file
        /// Documentation: https://developers.google.com/drive/v2/reference/files/update
        /// </summary>
        /// <param name="_service">a Valid authenticated DriveService</param>
        /// <param name="_uploadFile">path to the file to upload</param>
        /// <param name="_parent">Collection of parent folders which contain this file. 
        ///                       Setting this field will put the file in all of the provided folders. root folder.</param>
        /// <param name="_fileId">the resource id for the file we would like to update</param>                      
        /// <returns>If upload succeeded returns the File resource of the uploaded file 
        ///          If the upload fails returns null</returns>
        public static File updateFile(DriveService _service, string _uploadFile, string _parent,string _fileId)
        {

            if (System.IO.File.Exists(_uploadFile))
            {
                File body = new File();
                body.Title = System.IO.Path.GetFileName(_uploadFile);
                body.Description = "File updated by Diamto Drive Sample";
                body.MimeType = GetMimeType(_uploadFile);
                body.Parents = new List<ParentReference>() { new ParentReference() { Id = _parent } };

                // File's content.
                byte[] byteArray = System.IO.File.ReadAllBytes(_uploadFile);
                System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
                try
                {
                    FilesResource.UpdateMediaUpload request = _service.Files.Update(body, _fileId, stream, GetMimeType(_uploadFile));
                    request.Upload();
                    return request.ResponseBody;
                }
                catch (Exception e)
                {
                    Console.WriteLine("An error occurred: " + e.Message);
                    return null;
                }
            }
            else
            {
                Console.WriteLine("File does not exist: " + _uploadFile);
                return null;
            }

        }
开发者ID:leejongseok,项目名称:TeamProject,代码行数:44,代码来源:DaimtoGoogleDriveHelper.cs


示例19: TraverseDirDFS

        private static void TraverseDirDFS(DirectoryInfo directory, Folder folder)
        {
            try
            {
                var files = directory.GetFiles();
                foreach (var file in files)
                {
                    var myFile = new File(file.Name, file.Length);

                    folder.Files.Add(myFile);
                }

                var directories = directory.GetDirectories();
                foreach (var dir in directories)
                {
                    var newFolder = new Folder(dir.Name);

                    TraverseDirDFS(dir, newFolder);

                    folder.Folders.Add(newFolder);
                }
            }
            catch (UnauthorizedAccessException)
            {
                return;
            }
        }
开发者ID:georgimanov,项目名称:Data-Structures-and-Algorithms,代码行数:27,代码来源:Startup.cs


示例20: TraverseFilesAndFolders

        static void TraverseFilesAndFolders(string path, Folder folder)
        {
            try
            {
                foreach (var fileName in Directory.GetFiles(path))
                {
                    int fileSize = (int)(new FileInfo(fileName)).Length;

                    File file = new File(fileName, fileSize);

                    folder.Files.Add(file);
                }

                foreach (var directoryName in Directory.GetDirectories(path))
                {
                    folder.ChildFolders.Add(new Folder(directoryName));

                    TraverseFilesAndFolders(directoryName, folder.ChildFolders[folder.ChildFolders.Count - 1]);
                }
            }
            catch (UnauthorizedAccessException e)
            {
                Console.WriteLine(e.Message);
            }
        }
开发者ID:ivan4otopa,项目名称:SoftUni,代码行数:25,代码来源:TraverseAndSaveDirectoryContentsInATree.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# FileAccess类代码示例发布时间:2022-05-24
下一篇:
C# Figure类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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