package com.lxm.demos
import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.InputStream
import java.io.InputStreamReader
import java.io.OutputStream
import java.io.OutputStreamWriter
import java.io.PrintWriter
import java.io.Reader
import java.io.Writer
import java.util.Scanner
public class FileDemo
{
public static void main(String[] args) throws Exception{
File file = new File("C:/lxm01.txt")
File file02 = new File("C:/lxm2.txt")
if(file.exists()==false)
{
file.createNewFile()
}
//方法一:
//方法二:
Scanner scanner = new Scanner(file)
PrintWriter pWriter = new PrintWriter(file02)
String line = null
while(scanner.hasNext())
{
line = scanner.next()
pWriter.println(line)
System.out.println(line)
}
if(scanner!=null)
{
scanner.close()
}
if(pWriter!=null)
{
pWriter.flush()
pWriter.close()
}
}
}