字符串里少了一个"\":
File file = new File("c:\\1.txt");
if(file.exists()){
   file.delete();//删除File.txt文件
}
if(file.createNewFile()){
   FileOutputStream fouts = new FileOutputStream(file);
   fouts.write('3');
   fouts.close();
}else{
   out.println("文件创建失败");
}

解决方案 »

  1.   

    楼上说得对,或者把c:\\1.txt改为c:/1.txt
      

  2.   

    xiezhirong(流浪的猫):
      不是少"\"的问题,我试过,还是没找到该文件
      

  3.   

    这个程序最好用例外优化一下。如下:
    public class AboutFile { public static void main(String[] args) {
    AboutFile aF = new AboutFile();
    aF.createFile();
    } /**
     * 
     */
    private void createFile() {
    File file = new File("E:\\myjob\\first.doc");
    if(file.exists()){
       file.delete();//删除File.txt文件
    }
    try {
    if(file.createNewFile()){
       FileOutputStream fouts = new FileOutputStream(file);
       fouts.write('3');
       fouts.close();
    }
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }
    }
      

  4.   

    我也改成c:/1.txt,可是会告诉错误的路径和文件名
      

  5.   

    还可以再优化,比如说把close放在finally里面。
      

  6.   

    还是不行啊,是不是我把程序放在linux系统下,运行的时候是在windows系统下的缘故,显示是建立成功,但总是不能在指定的目录下找到我刚刚建立的新文件。