import java.io.*;
public class FileTest {

/**
 * Method main
 *
 *
 * @param args
 *
 */
public static void main(String[] args) {
// TODO: 在这添加你的代码
File f = new File("1.txt");
if(f.exists())//判断,假如这个文件存在,就调用delete删除它
{
f.delete();
}
else
{
f.createNewFile();
}
System.out.println("File name:" + f.getName());
    System.out.println("File path:" + f.getPath());
    System.out.println("File abs path:" + f.getAbsoluteFile());
    System.out.println("File Parent:" + f.getParent());
    System.out.println(f.exists()?"exist":"not exist");
    System.out.println(f.canRead()?"read":"not read");
    System.out.println(f.canWrite()?"write":"not write");
    System.out.println(f.isDirectory()?"directory":not directory);
    System.out.println("File last modified:" + f.lastModified());
    
    }
}
错误提示  TODO:在这添加你的代码                               Line 14    
  

解决方案 »

  1.   

    import java.io.*;
    public class FileTest {

    /**
     * Method main
     *
     *
     * @param args
     *
     */
    public static void main(String[] args) throws IOException{
    // TODO: 在这添加你的代码
    File f = new File("1.txt");
    if(f.exists())//判断,假如这个文件存在,就调用delete删除它
    {
    f.delete();
    }
    else
    {
    f.createNewFile();
    }
    System.out.println("File name:" + f.getName());
        System.out.println("File path:" + f.getPath());
        System.out.println("File abs path:" + f.getAbsoluteFile());
        System.out.println("File Parent:" + f.getParent());
        System.out.println(f.exists()?"exist":"not exist");
        System.out.println(f.canRead()?"read":"not read");
        System.out.println(f.canWrite()?"write":"not write");
        System.out.println(f.isDirectory()?"directory":"not directory");
        System.out.println("File last modified:" + f.lastModified());
        
        }
    }
      

  2.   

    import java.io.*;
    public class FileTest {/**
    * Method main
    *
    *
    * @param args
    *
    */
    public static void main(String[] args) throws IOException
     {
    // TODO: 在这添加你的代码
    File f = new File("1.txt");
    if(f.exists())//判断,假如这个文件存在,就调用delete删除它
    {
    f.delete();
    }
    else
    {
    f.createNewFile();
    }
    System.out.println("File name:" + f.getName());
    System.out.println("File path:" + f.getPath());
    System.out.println("File abs path:" + f.getAbsoluteFile());
    System.out.println("File Parent:" + f.getParent());
    System.out.println(f.exists()?"exist":"not exist");
    System.out.println(f.canRead()?"read":"not read");
    System.out.println(f.canWrite()?"write":"not write");
    System.out.println(f.isDirectory()?"directory":"not directory");
    System.out.println("File last modified:" + f.lastModified());}
    }