在项目文件夹下建立一个以utf8格式编码的reader.txt文件,里边输入四个汉字【科文学院】,然后编程将这个文件的内容复制到writer.txt文件中,文件编码也要是utf8格式。 部分参考代码如下: FileInputStream in = new FileInputStream("reader.txt"); InputStreamReader isr = new InputStreamReader(in,"utf8"); BufferedReader br = new BufferedReader(isr); FileOutputStream out = new FileOutputStream("writer.txt"); OutputStreamWriter osw = new OutputStreamWriter(out,"utf8"); BufferedWriter bw = new BufferedWriter(osw);
时间: 2024-02-27 12:55:39 浏览: 62
江苏师范大学科文学院VB编程题答案.docx
好的,根据您的要求,以下是JAVA代码实现:
```
import java.io.*;
public class FileCopy {
public static void main(String[] args) {
try {
FileInputStream in = new FileInputStream("reader.txt");
InputStreamReader isr = new InputStreamReader(in, "utf8");
BufferedReader br = new BufferedReader(isr);
FileOutputStream out = new FileOutputStream("writer.txt");
OutputStreamWriter osw = new OutputStreamWriter(out, "utf8");
BufferedWriter bw = new BufferedWriter(osw);
String line = "";
while ((line = br.readLine()) != null) {
bw.write(line);
}
br.close();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
请确保在项目文件夹下已经存在名为"reader.txt"的文件,并且其中已经输入了"科文学院"四个汉字。运行后,程序会将"reader.txt"文件中的内容复制到新创建的"writer.txt"文件中,编码方式为utf8格式。
阅读全文