标签:led 删除 equals file sharp i++ get blog false
public class FileDemo { public static File file; public static void main(String args[]) { String s = args[0]; String f = "F:"+File.separator+"work"+File.separator+"60"+File.separator+"60.txt"; System.out.println("-->"+s+"<--"); System.out.println("开始运行"); if(s.equals("c")) { System.out.println("创建:检查文件是否存在"); boolean b = existsFile(f); if(b){ System.out.println("文件已经存在"); }else{ System.out.println("文件不存在,可以创建"); createFile(f); } }else if(s.equals("d")) { System.out.println("删除:检查文件是否存在"); boolean b = existsFile(f); if(b) { System.out.println("删除"); deleteFile(f); }else{ System.out.println("文件不存在,无法删除"); } } getPath(); list(); listFiles(); } public static void createFile(String f) { try { file.createNewFile(); } catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } public static void deleteFile(String f) { file.delete(); } public static boolean existsFile(String f) { file = new File(f); if(file.exists()) { return true; }else{ return false; } } public static boolean isFile(String f) { if(file.isFile()) { return true; }else{ return false; } } public static boolean isPath(String f) { if(file.isDirectory()) { return true; }else{ return false; } } public static void getPath() { System.out.println(file.getPath()); System.out.println(file.getParent()); } //列出目录 public static void list() { File file2 = new File("F:"+File.separator+"work"); String p[] = file2.list(); for(int i = 0; i < p.length ; i++) { System.out.println( p[i]); } } //列出目录 public static void listFiles() { File file2 = new File("F:"+File.separator+"work"); File p[] = file2.listFiles(); for(int i = 0; i<p.length; i++) { System.out.println(p[i]); } }
标签:led 删除 equals file sharp i++ get blog false
原文地址:http://www.cnblogs.com/achengmu/p/7083232.html