日期:2014-05-18  浏览次数:20803 次

C# 文件操作

文件读取:

            Console.WriteLine(Directory.Exists("H:\\CopyFiles1.java"));
            return;
            StreamReader objReader = new StreamReader("H:\\CopyFiles1.java");
          

            
            string sLine = "";
            ArrayList arrText = new ArrayList();
            while (sLine != null)
            {
                sLine = objReader.ReadLine();
                if (sLine != null)
                    Console.WriteLine(sLine);
                    //arrText.Add(sLine);
            }
            objReader.Close();
            //foreach (string sOutput in arrText)
            //    Console.WriteLine(sOutput);
            Console.ReadLine();

?文件写操作:

?

?? ? ? private void writeImportFiles(string str)

        {
            string filename = Path.Combine(folderPathTextBox.Text, "importFiles.txt");
            FileStream fs = new FileStream(filename, FileMode.Append, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine(str);
            sw.Close();
            fs.Close();
        }
?