package cn.com.process;import java.io.*;public class FileInputStream {
public static void main(String args[]) throws IOException {
char c;
File f = new File("d://c.txt");
FileOutputStream fw = new FileOutputStream(f);
//String name="English";
String name = "我要输入中文!";//输入中文为什么是乱码?如何处理?
for(int i=0;i<name.length();i++){
c=name.charAt(i);
fw.write(c);
}
fw.flush();
fw.close();
BufferedReader reader = null;
try {
FileReader fr = new FileReader(f);
reader = new BufferedReader(fr);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String s = null; s = reader.readLine();
for (int i = 0; i < s.length(); i++) {
c = s.charAt(i);
System.out.print(c);
}
reader.close(); }
public static void main(String args[]) throws IOException {
char c;
File f = new File("d://c.txt");
FileOutputStream fw = new FileOutputStream(f);
//String name="English";
String name = "我要输入中文!";//输入中文为什么是乱码?如何处理?
for(int i=0;i<name.length();i++){
c=name.charAt(i);
fw.write(c);
}
fw.flush();
fw.close();
BufferedReader reader = null;
try {
FileReader fr = new FileReader(f);
reader = new BufferedReader(fr);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String s = null; s = reader.readLine();
for (int i = 0; i < s.length(); i++) {
c = s.charAt(i);
System.out.print(c);
}
reader.close(); }
public static void main(String args[]) throws IOException { File f = new File("d://c.txt");
FileOutputStream fw = new FileOutputStream(f);
//String name="English";
String name = "我要输入中文!";//输入中文为什么是乱码?如何处理?
byte[] on = name.getBytes();
fw.write(on,0,on.length);
fw.flush();
fw.close();
BufferedReader reader = null;
try {
FileReader fr = new FileReader(f);
reader = new BufferedReader(fr);
String s = null;
s = reader.readLine();
System.out.print(s);
reader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
直接用PrintWriter out = new PrintWriter(new FileOutputStream("xxx.txt"));
out.println("中文滴");就这样,想写啥直接往里整就行了,字符就用字符流搞哦。