码迷,mamicode.com
首页 > 其他好文 > 详细

文件读写

时间:2018-07-03 00:20:14      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:nts   pac   flush   port   rac   int   stack   rgs   main   

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

          

文件读写

标签:nts   pac   flush   port   rac   int   stack   rgs   main   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!