如何创建一个文件

解决方案 »

  1.   

    方法多种,如果准备立即写东西的话,可以:
    FileWriter fw = new FileWriter("文件路径名称");
    fw.write("..........");
    fw.close();
      

  2.   


    String filePath = "F:/2012.txt";
    File file = new File(filePath);
    System.out.println(file.exists());

    try {
       file.createNewFile();
    } catch (IOException e) {
       e.printStackTrace();
    }System.out.println(file.exists());
      

  3.   

    System.out.println(file.exists());
    这个是什么意思?是输出文件路径吗?
      

  4.   

    创建  并写入内容
    用PrintWriter类
    PrintWriter  output=null;
    try{
      output=new PrintWriter(new FileOutputStream("out.txt"));
    }
    catch(FileNotFoundException e){
    }
    Scanner in=new Scanner(System.in);
    String in=in.nextLine();
    output.println(in);
    output.close();
    就可以了
      

  5.   

    String filePath = "F:/2012.txt";
    File file = new File(filePath);
    System.out.println(file.exists());
            
    try {
       file.createNewFile();
    } catch (IOException e) {
       e.printStackTrace();
    }System.out.println(file.exists());