输出流

版权声明:JAVA https://blog.csdn.net/weixin_43190126/article/details/84894574
package com.qyl.outString;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import org.junit.Test;

public class TestOutString {
	
	//用字节流对文本的读取及添加
		@Test
		public void outString() throws Exception {
			FileOutputStream file = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\input.txt",true);
			String str = "儒雅之风,君子之道";
			file.write(str.getBytes());
			file.close();
		}	
		
		//用字符流对文本的读取及添加
		@Test
		public void testFileWrite() throws Exception{
			FileWriter w = new FileWriter("C:\\Users\\Administrator\\Desktop\\input.txt", true);
			w.write("滚吧");
			w.append(",去你妈的");
			w.close();	
		}
}

猜你喜欢

转载自blog.csdn.net/weixin_43190126/article/details/84894574