//读取目录 下的所有非隐藏文件夹或文件 public List<FileItem> GetList(string path) { int i; string[] folders = Directory.GetDirectories(path); string[] files = Directory.GetFiles(path); List<FileItem> list = new List<FileItem>(); foreach (string s in folde…
windows下使用java.io.File.delete()方法删除文件时,返回值为true. 但是本地文件仍然存在,也就是说没有删除成功. 这时候你要检查下你传进来的文件目录格式是否正确. 正确:d://dir//111.jpg 错误:d:\dir\111.jpg File f = new File("d://dir//111.jpg"); if (f.exists()) { System.err.println("文件存在"); boolean t = f.d…
using System; using System.IO; class Test { public static void Main() { string path = @"c:\temp\MyTest.txt"; if (!File.Exists(path)) { // Create a file to write to. using (StreamWriter sw = File.CreateText(path)) { sw.WriteLine("Hello"…
在实际开发中,如果用的文件名不能确定位置.或名字.可以使用GUID类来命名函数.Guid 结构标识全局唯一标示符.其NewGuid结构可以初始化一个新历.该方法语法格式如下: public static Guid NewGuid(); return: 初始化后的实例. 源码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Dr…
error msg: System.Threading.Tasks.TaskCanceledException: The operation was canceled. ---> System.IO.IOException: Unable to read data from the transport connection: Operation canceled. ---> System.Net.Sockets.SocketException: Operation canceled --- E…
实现一个 TextWriter,使其以一种特定的编码向流中写入字符. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace StreamReadWrite { class Program { static void Main(string[] args) { // Get the directories currently o…
为文件提供 Stream,既支持同步读写操作,也支持异步读写操作. using System; using System.IO; using System.Text; class Test { public static void Main() { string path = @"c:\temp\MyTest.txt"; // Delete the file if it exists. if (File.Exists(path)) { File.Delete(path); } //Cr…