package itcast.video0101;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class I_11_IO_PrintDemo {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String path = "C:\\Users\\Administrator\\Desktop\\book2\\";
printWriter(path + "prontWriter.txt");
}
/*
* 使用PrintWriter读键盘和 写文件
*/
public static void printWriter(String fileName) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
// PrintWriter pw = new PrintWriter(System.out);
PrintWriter pw = new PrintWriter(new FileWriter(fileName));
File file = new File(fileName);
if (!file.exists()) {
file.createNewFile();
}
String line = null;
while ((line = bf.readLine()) != null) {
if (line.equals("over"))
break;
pw.println(line);
pw.flush();
}
pw.close();
bf.close();
}
}
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class I_11_IO_PrintDemo {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String path = "C:\\Users\\Administrator\\Desktop\\book2\\";
printWriter(path + "prontWriter.txt");
}
/*
* 使用PrintWriter读键盘和 写文件
*/
public static void printWriter(String fileName) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
// PrintWriter pw = new PrintWriter(System.out);
PrintWriter pw = new PrintWriter(new FileWriter(fileName));
File file = new File(fileName);
if (!file.exists()) {
file.createNewFile();
}
String line = null;
while ((line = bf.readLine()) != null) {
if (line.equals("over"))
break;
pw.println(line);
pw.flush();
}
pw.close();
bf.close();
}
}