标签:中文 stat 输入 str int 输出 bsp [] row
字符流的操作:
字节流的操作,是直接映射文件的:file->文件
字符流的操作是需要存在缓存区的:file->缓冲区->文件 (中文处理,一般用字符流)
public static void main(String args[]) throws Exception
{
File file = new File("F:"+File.separator+"work"+File.separator+"work"+File.separator+"demo.txt");
String str = args[0];
if(str.equals("w"))
{
write(file);
}else if(str.equals("r"))
{
read(file);
}else{
System.out.println("您没有传递任何参数");
}
}
public static void write(File file) throws Exception
{
//字符输出
Writer out = null;
out = new FileWriter(file,true);
String str = "你好啊盆友\r\n";
out.write(str);
out.close();
}
public static void read(File file) throws Exception
{
//字符输入流
Reader input = null;
//通过子类直接实例化操作
input = new FileReader(file);
//开辟空间接收读取的内容
char b[] = new char[(int) file.length()];
for(int i = 0; i < b.length; i++)
{
//一个一个的读取数据
b[i] = (char) input.read();
}
//输出内容,之间转换
System.out.println(new String(b));
input.close();
}
标签:中文 stat 输入 str int 输出 bsp [] row
原文地址:http://www.cnblogs.com/achengmu/p/7109387.html