学习笔记 - BufferedWriter将字符串通过字符缓冲流写入文件

public class BufferedWriterTest {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		BufferedWriterTest bwt = new BufferedWriterTest();
		bwt.bufferedWriter("呵可呵榀", "d:\\test2.java");
	}
	
	public void bufferedWriter(String str,String filePath){
		File file = new File(filePath);
		FileWriter fw = null;
		BufferedWriter bw = null;
		try {
			fw = new FileWriter(file);
			bw = new BufferedWriter(fw);
			bw.write(str);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			try {
				bw.close();
				fw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
	}
}

你可能感兴趣的:(Java基础知识)