Source Code เพื่อ การศึกษา
j0601.java
j0601
// ::::: โปรแกรมลำดับที่ 21 // 1. การแสดงรายละเอียดของแฟ้ม c:/windows/win.ini // 2. http://www.yonok.ac.th/pmy/j2sdk-1_4_2-doc.zip // 3. http://www.exampledepot.com/egs/java.io/ import java.io.*; class j0601 { public static void main (String args[]) throws IOException { File f = new File("c:/windows/win.ini"); System.out.println("getName: "+f.getName()); System.out.println("getPath: "+f.getPath()); System.out.println("getAbsolutePath: "+f.getAbsolutePath()); System.out.println("exists: "+f.exists()); System.out.println("isFile: "+f.isFile()); System.out.println("isDirectory: "+f.isDirectory()); System.out.println("canWrite: "+f.canWrite()); System.out.println("canRead: "+f.canRead()); System.out.println("length: "+f.length()); // create hello1.txt have 0 byte File file = new File("hello1.txt"); boolean success = file.createNewFile(); // 0 byte // move hello1.txt to hello2.txt File file2 = new File("hello2.txt"); success = file.renameTo(file2); // move hello2.txt to c:/hello2.txt File b = new File("c:/"); success = file2.renameTo(new File(b, file2.getName())); // not found file to delete so is false success = (new File("hello2.txt")).delete(); System.out.println(success); // false // found file to delete so is true success = (new File("c:/hello2.txt")).delete(); System.out.println(success); // true } }
ปรับปรุงโปรแกรม source.pl : 2553-03-20