写入内容到文件中

package com.zhiru;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class WriteToFile {
	private String fName;

	WriteToFile(String f) {
		fName = f;

	}

	public void writeToFile(String what) throws IOException {
		//想文件中追加新的内容
		OutputStream out = new FileOutputStream(new File(fName),true);
		byte[] b = what.getBytes();
		out.write(b);
		out.flush();
		out.close();
	}
}

你可能感兴趣的:(写入内容到文件中)