PrintWriter字符打印流
/**
* PrintWriter字符打印流
*
* @author xiazhang
* @date 2017-6-4
*/
public class PrintWriterTest {
/**
* 使用打印流写入
* @param file
*/
private static void writerFileByPrintWriter(File file){
if(file != null && file.exists()){
try {
PrintWriter pw = new PrintWriter(file);
pw.write("xiazhang are you ok? ");
pw.write("what's your name?");
pw.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
System.out.println("文件为空或不存在!");
}
}
public static void main(String[] args) {
File file = new File("fileTest2.txt");
writerFileByPrintWriter(file);
}
}