怎么删除文件啊?我问了一个人,那人说先得定位,看文件在什么地方!然后删除!到底怎么做啊!
我做的是一个系统,有上传上来的文件,现在要我做删除这个功能!

解决方案 »

  1.   

    File f = new File(FilePathAndName);
    f.delete();
    当然需要知道文件在什么地方了!
      

  2.   

    import java.text.*;
    import java.util.*;
    import java.io.*;public class ghytest { public static String getYearMonthDayOfchina(String type) {
    SimpleDateFormat ghyghost = new SimpleDateFormat(type);
    return ghyghost.format(new Date());
    } public static void main(String[] args) {
    File ghy=new File("c:\1.txt");
    if (ghy.exists()) 
    {ghy.delete();
    System.out.print("OK");
    }
    else
    {
    System.out.print("no");
    }
    }}我写了一个实例,但删除不了c:\1.txt怎么办?
      

  3.   

    File ghy=new File("c:\1.txt");
    ----------------
    你这种写法编译都通不过怎么删?
      

  4.   

    import java.text.*;
    import java.util.*;
    import java.io.*;public class ghytest { public static String getYearMonthDayOfchina(String type) {
    SimpleDateFormat ghyghost = new SimpleDateFormat(type);
    return ghyghost.format(new Date());
    } public static void main(String[] args) {
    File ghy=new File("c:","1.txt");
    System.out.print(ghy.getName());
    if (ghy.exists()) 
    {ghy.delete();
    System.out.print("OK");
    }
    else
    {
    System.out.print("no");
    }
    }}
    楼主这样OK
      

  5.   

    File ghy=new File("c:/1.txt");
    File ghy=new File("c:\\1.txt");这样都可以的
      

  6.   

    JAVA里“\”是转义符,所以要用二个才行,File ghy=new File("c:\\1.txt");