文件读写

Posted 4910yxq

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了文件读写相关的知识,希望对你有一定的参考价值。

package 文件读取;
import java.io.*;
import java.util.*;
public class File {
 public static void main(String[] args)throws Exception
    {
            FileReader file_source=null;
            FileWriter file_destination=null;
            try
            {
                    file_source=new FileReader("D:/a.txt");
                    file_destination=new FileWriter("D:/b.txt");
                    char[] buf=new char[1024];
                    int len=0;
                    while((len=file_source.read(buf))!=-1)
                    {       
//                            Sort(buf);
                            Arrays.sort(buf);
                            System.out.println(buf);
                           
                            file_destination.write(buf,0,len);
                            file_destination.flush();
                    }
            }
            catch(IOException e)
            {
                    e.printStackTrace();
            }
            finally
            {
                    try
                    {
                            if(file_source!=null)
                                    file_source.close();
                    }
                    catch(IOException e)
                    {
                            e.printStackTrace();
                    }
                    try
                    {
                            if(file_destination!=null)
                                    file_destination.close();
                    }
                    catch(IOException e)
                    {
                            e.printStackTrace();
                    }
                   
            }
    }
}

          




















































以上是关于文件读写的主要内容,如果未能解决你的问题,请参考以下文章

数据清洗文件操作--csv txt文件读写excel文件读写数据库文件读写

VB读写INI文件

Python文件读写

MFC怎么读写EXCEL文件

Python文件读写

C++ 文件的随机读写