展开全部
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.StringReader;
import java.io.StringWriter;
public class ReverseText {
public static void main(String[] args) throws Exception {
String from="c:/1.txt"; //源文件
String to="c:/2.txt"; //反转后的新文件
FileReader reader = new FileReader(from);
FileWriter writer = new FileWriter(to);
StringWriter sWriter = new StringWriter();
int readed = reader.read();
while(readed!=-1){
//writer.write(readed);
sWriter.write(readed);
readed = reader.read();
}
StringBuffer buffer = sWriter.getBuffer();
for(int i= buffer.length()-1;i>=0;i--){
writer.write(buffer.charAt(i));
}
writer.close();
sWriter.close();
reader.close();
}
}
import java.io.FileReader;
import java.io.FileWriter;
import java.io.StringReader;
import java.io.StringWriter;
public class ReverseText {
public static void main(String[] args) throws Exception {
String from="c:/1.txt"; //源文件
String to="c:/2.txt"; //反转后的新文件
FileReader reader = new FileReader(from);
FileWriter writer = new FileWriter(to);
StringWriter sWriter = new StringWriter();
int readed = reader.read();
while(readed!=-1){
//writer.write(readed);
sWriter.write(readed);
readed = reader.read();
}
StringBuffer buffer = sWriter.getBuffer();
for(int i= buffer.length()-1;i>=0;i--){
writer.write(buffer.charAt(i));
}
writer.close();
sWriter.close();
reader.close();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先用字节流把源文件读取到内存中,转换为字符流以后,倒叙。输出!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-03-21
展开全部
代码记不太清楚了,所以只能给你思路:先用字节流把源文件读取到内存中,转换为字符流再输出,你可以查看一下流的代码就能明白
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询