简体   繁体   English

文件信息 - c# Vs2008

[英]Fileinfo - c# Vs2008

Can I use FileInfo as such:我可以这样使用 FileInfo:

 FileInfo fileInfo = new FileInfo(@"\\mymachine\downloads\;\\yourmachine\Log\" +  "11.txt");
StreamWriter sw = fileInfo.CreateText();
sw.WriteLine("write some data");
sw.Close();

My lead thinks it can be used as such but I get an exception when I run that code..我的领导认为它可以这样使用,但是当我运行该代码时出现异常..

Exception:例外:

System.IO.DirectoryNotFoundException Could not find a part of the path

He thinks he can do a fake load balance and/or depending on which share is available the code will place an order file to be processed.他认为他可以做一个虚假的负载平衡和/或根据可用的共享,代码将放置一个要处理的订单文件。 I do not agree with his thinking but he my boss and i gotta do his biding..我不同意他的想法,但他是我的老板,我必须服从他的要求。

The FileInfo constructor takes the path to a single file; FileInfo 构造函数获取单个文件的路径; what you're passing it is not a valid file name, so I'd expect an ArgumentException .你传递的不是一个有效的文件名,所以我期待一个ArgumentException What are you actually trying to accomplish here?你到底想在这里完成什么?

FileInfo just doesn't work like that. FileInfo 只是不能那样工作。 You're going to have to use something like File.Exists to see which file is available and then write code to write to one share or the other.您将不得不使用 File.Exists 之类的东西来查看哪个文件可用,然后编写代码以写入一个或另一个共享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM