从键盘输入将输入写入到文件



import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


public class TestReflect {

 public static void main(String[] args) {
  TestReflect  tf=new TestReflect();
  tf.copyFile1();
 }
 
 public TestReflect(){
  System.out.println("TestReflect");
 }
 public void play(String str){
  System.out.println(str);
 }
 public void copyFile1() {
  //File srcFile = new File("E://test1.txt");
  File dstFile = new File("E://test2.txt");
  BufferedReader in = null;
  BufferedWriter out = null;
  BufferedReader br =null;
  try {
   br =new BufferedReader(new InputStreamReader(System.in));
   in = br;
    //new FileReader(srcFile));
   out = new BufferedWriter(new FileWriter(dstFile));
    out.write(br.readLine()+"\r\n");
  }catch (Exception e) {
   // TODO: handle exception
   e.printStackTrace();
  }finally {
   if(in != null) {
    try {
     in.close();
    }catch (Exception e) {
     // TODO: handle exception
     e.printStackTrace();
    }
   }
   
   if(out != null) {
    try {
     out.close();
    }catch (Exception e) {
     // TODO: handle exception
     e.printStackTrace();
    }
   }
  }
 }
}

你可能感兴趣的:(Java-基础知识)