首页 > 其他 > 详细

文件读写

时间:2018-07-02 23:52:38      阅读:146      评论:0      收藏:0      [点我收藏+]

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();
                    }
                   
            }
    }
}

          

文件读写

原文:https://www.cnblogs.com/4910yxq/p/9256393.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!