/*项目根路径下有text.txt文件,内容如下:
我爱java
123456
利用IO流的知识读取text.txt文件的内容反转后写入text1.txt文件中*/
import java.io.*;
public class Deom04 {
public static void main(String[] args) throws IOException {
/* FileInputStream fis = new FileInputStream("Array\\src\\Day08\\Homework\\text.txt");
FileOutputStream fos=new FileOutputStream("Array\\src\\Day08\\Homework\\text1.txt");
StringBuilder str = new StringBuilder();
int len;
byte[] bytes = new byte[1024];
while ((len=fis.read(bytes))!=-1){
str.append(new String(bytes));
}
fos.write(str.reverse().toString().getBytes());
fis.close();
fos.close();*/
BufferedReader br = new BufferedReader(new FileReader("Array\\src\\Day08\\Homework\\text.txt"));
BufferedWriter bw = new BufferedWriter(new FileWriter("Array\\src\\Day08\\Homework\\text.txt"));
StringBuilder str = new StringBuilder();
String data;
while ((data=br.readLine())!=null){
str.append(data);
}
bw.write(str.reverse().toString());
}
}
IO
最新推荐文章于 2021-03-06 15:28:33 发布