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(); }
解决方案 »
- 关于junit的问题求助
- 如何真正实现屏蔽键盘输入的jtextfield。。。。。。。高分。。急
- 我在windows2000中map了一个网络的地址到E:盘,有没有办法用java把这个路径转化为网络路径啊!
- 高手!高手!
- 100分,求JTree使用简单问题,在线等待
- java程序改错
- 为什么我一执行:rs.getInt(1),就会抛出下面的异常来??
- 请教:一道关于线程non-runnable的单选题。
- 为什么我的java小应用程序不能在ie中显示
- 谁在WL下做过JMS的开发,请进来帮帮我,一个小问题。
- java怎样截取或者叫触发ie页面上rul和按钮的事件
- 问题编号012:如何在本页获取表单中的值?
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("中文滴");就这样,想写啥直接往里整就行了,字符就用字符流搞哦。