依据菜鸟教程的JAVA教程,代码练习如下:
import java.io.*;
public class MakeFile {
public static void main(String[] args) throws IOException {
File f = new File("make-file.txt");
FileOutputStream fop = new FileOutputStream(f);
OutputStreamWriter writer = new OutputStreamWriter(fop,"UTF-8");
writer.append("中文输入");
writer.append("\r\n");
writer.append("English");
writer.close();
fop.close();
FileInputStream fip = new FileInputStream(f);
InputStreamReader reader = new InputStreamReader(fip,"UTF-8");
StringBuffer sb = new StringBuffer();
while (reader.ready()) {
sb.append((char) reader.read());
}
System.out.println(sb.toString());
reader.close();
fip.close();
}
}
输出如下:
中文输入
English
另外添加菜鸟教程的JAVA数组教程地址:
妈的!!!给蚊子叮死了!!!!!!!!!!!!!!!!!!!!