用java实现文本文件内容的倒序

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 20:24   4081   0

/*
* Main.java
*
* Created on 2007年11月6日, 上午10:00
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package proj2;
import java.io.*;
import java.util.*;
/**
*
* @author user
*/
public class Main {


/** Creates a new instance of Main */
public Main() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException,IOException{
// TODO code application logic here
File f=new File("d://3.txt");
File f1=new File("d://4.txt");
BufferedReader b=new BufferedReader(new FileReader(f));
BufferedWriter b1=new BufferedWriter(new FileWriter(f1));
List temp=new ArrayList();
String data=null;
while((data=b.readLine())!=null)
{
temp.add(data);
}
for(int i=temp.size()-1;i>=0;i--)
{
String str=(String)temp.get(i);
b1.write(str);
b1.write('/n');
}
b.close();
b1.close();
}

}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP