试试 File file=new File(".//test","test.txt");

解决方案 »

  1.   

    有“/test”这个目录吗? 用file.createNewFile必须保证目录存在。
      

  2.   

    在运行你的程序的根目录下,必须有 test 这个目录,否则就会出错!也就是说createNewFile 只能够新键一级文件(或者目录)
      

  3.   

    我运行了你的程序,先建C:\test这个目录,运行
    import java.io.*;
    class  newFile
    {
    public static void main(String[] args)throws IOException
    {
      File file=new File("C:/test","test.txt");
      try{
           if(!file.exists())
                      file.createNewFile();
         }
                catch(Exception e){e.printStackTrace();}
                System.out.println(file.getName());
              }}
    就都正常了,也就是说你的"/test"不是一个合法的目录,你可以用isDirectory() 方法判断一下"/test"是不是目录.
      

  4.   

    必须有 test 这个目录,同时
    File file=new File("/test","test.txt");
    应改为
    File file=new File("test","test.txt");
      

  5.   

    应该是 File f=new File("C:\\Test.txt");