| new File ( path ) | ใช้สร้าง Object File |
|---|---|
| new File ( path, filename ) | ใช้สร้าง Object File |
| mkdir() | ใช้ สร้าง folder ใหม่ โดยถ้าสร้างสำเร็จจะคืนค่า true มาให้ |
| createNewFile() | ใช้ สร้าง file ใหม่ โดยถ้าสร้างสำเร็จจะคืนค่า true มาให้ |
| delete() | ใช้ลบ file หรือ folder โดยถ้าลบสำเร็จจะคืนค่า true มาให้ |
| renameTo() | ใช้เปลี่ยนชื่อ file หรือ folder โดยถ้าเปลี่ยนสำเร็จจะคืนค่า true มาให้ |
| length() | ใช้คืนค่า ขนาด ของ folder หรือ file โดยมีหน่วยเป็ฯ byte |
| getParent() | ใช้คืนค่า directory ของ file หรือ folder |
| getName() | ใช้คืนค่า ชื่อของ file หรือ folder |
| getAbsolutePath() | ใช้คืนค่า absolute path ของ file หรือ folder |
| isHidden() | ใช้ตรวจสอบว่า folder หรือ file ถูกซ่อนอยู่หรือไม่ |
| canRead() | ใช้ตรวจสอบว่า folder หรือ file สามารถอ่านได้หรือไม่ |
| canWrite() | ใช้ตรวจสอบว่า folder หรือ file สามารถเขียนได้หรือไม่ |
method:new File ( path );
return type:File
content:ใช้สร้าง Object File
example:File file = new File ( "C:/panda.jpg" );
method:new File ( path, filename );
return type:File
content:ใช้สร้าง Object File
example:File file = new File ( "C:/", "panda.jpg" );
method:mkdir ();
return type:boolean
content:ใช้ สร้าง folder ใหม่ โดยถ้าสร้างสำเร็จจะคืนค่า true มาให้
example:File folder = new File ( "C:/bamboo" ); if ( folder.mkdir () ) { System.out.println ( "Make Folder Success." ); }
method:createNewFile ();
return type:boolean
content:ใช้ สร้าง file ใหม่ โดยถ้าสร้างสำเร็จจะคืนค่า true มาให้
example:File file = new File ( "C:/bamboo.txt" ); if ( file.createNewFile () ) { System.out.println ( "Make File Success." ); }
method:delete ();
return type:boolean
content:ใช้ลบ file หรือ folder โดยถ้าลบสำเร็จจะคืนค่า true มาให้
example:File file = new File ( "C:/bamboo.txt" ); if ( file.delete () ) { System.out.println ( "Delete File Success." ); }
method:renameTo ( object_file );
return type:boolean
content:ใช้เปลี่ยนชื่อ file หรือ folder โดยถ้าเปลี่ยนสำเร็จจะคืนค่า true มาให้
example:File file = new File ( "C:/bamboo.txt" ); File file_rename = new File ( "C:/bamboolabcode.txt" ); if ( file.renameTo ( file_rename ) ) { System.out.println ( "Rename File Success." ); }
method:length ();
return type:long
content:ใช้คืนค่า ขนาด ของ folder หรือ file โดยมีหน่วยเป็ฯ byte
example:File file = new File ( "C:/bamboo.txt" ); long size_file = file.length ();
method:getParent ();
return type:String
content:ใช้คืนค่า directory ของ file หรือ folder
example:File file = new File ( "C:/project/bamboo.txt" ); String directory = file.getParent ();
method:getName ();
return type:String
content:ใช้คืนค่า ชื่อของ file หรือ folder
example:File file = new File ( "C:/project/bamboo.txt" ); String filename = file.getName ();
method:getAbsolutePath ();
return type:String
content:ใช้คืนค่า absolute path ของ file หรือ folder
example:File file = new File ( "C:/project/bamboo.txt" ); String absolute_path = file.getAbsolutePath ();
method:isHidden ();
return type:boolean
content:ใช้ตรวจสอบว่า folder หรือ file ถูกซ่อนอยู่หรือไม่
example:File file = new File ( "C:/project/bamboo.txt" ); if ( file.isHidden () ) { System.out.println ( "File is hidden." ); }
method:canRead ();
return type:boolean
content:ใช้ตรวจสอบว่า folder หรือ file สามารถอ่านได้หรือไม่
example:File file = new File ( "C:/project/bamboo.txt" ); if ( file.canRead () ) { System.out.println ( "File can read." ); }
method:canWrite ();
return type:boolean
content:ใช้ตรวจสอบว่า folder หรือ file สามารถเขียนได้หรือไม่
example:File file = new File ( "C:/project/bamboo.txt" ); if ( file.canWrite () ) { System.out.println ( "File can write." ); }