缓冲字符流的使用BufferedReader和BufferedWriter

1.BufferedReader和BufferedWriter

                BufferedReader br = null;
		BufferedWriter bw = null;
		try {
			//先创建FileReader对象
			FileReader fr = new FileReader("/Users/hh/Desktop/test11.txt");
			br = new BufferedReader(fr);
			//创建FileWriter的对象
			FileWriter fw = new FileWriter("/Users/hh/Desktop/test变.txt");
			bw = new BufferedWriter(fw);
			//循环读取文件
			String s = "";
			while ((s = br.readLine())!=null) {
//				System.out.print(s);
				//输出到磁盘
				bw.write(s+"\r\n");
			}
		} catch (Exception e) {
			// TODO: handle exception
		}finally {
			try {
				br.close();
				bw.close();
			} catch (Exception e2) {
				// TODO: handle exception
			}
		}

你可能感兴趣的:(java)