| new RandomAccessFile ( object_file, mode ) | ใช้สร้าง Object RandomAccessFile |
|---|---|
| new RandomAccessFile ( path, mode ) | ใช้สร้าง Object RandomAccessFile |
| close() | ใช้ปิดการทำงานของ Object RandomAccessFile |
| length() | ใช้คืนค่า ขนาด ของ file ( หน่วย byte ) |
| seek() | ใช้ เลื่อน pointer ไปยังตำแหน่งที่กำหนดใน file |
| skipBytes() | ใช้ ข้ามข้อมูลตามจำนวนที่กำหนด ใน file |
| setLength() | ใช้กำหนด ขนาด สูงสุด ให้กับ file ( หน่วย byte ) |
| read() | ใช้อ่านค่า ascii ของข้อมูล ณ ตำแหน่งปัจจุบันที่ pointer ชี้อยู่ |
| readLine() | ใช้อ่านค่า ข้อมูล ครั้งละ 1 บรรทัด |
| write(); | ใช้เขียนข้อมูล ลงไฟล์ โดยเขียนข้อมูลจากรหัส ascii ที่กำหนด |
| writeChar() | ใช้เขียนข้อมูล ลงไฟล์ โดยเขียนข้อมูลจากรหัส ascii ที่กำหนด |
method:new RandomAccessFile ( object_file, mode );
return type:RandomAccessFile
content:ใช้สร้าง Object RandomAccessFile
example:File file = new File ( "C:/bamboo.txt" ); RandomAccessFile random_access_file = new RandomAccessFile ( file, "rw" );
comment:mode คือกำหนดว่าอ่านได้อย่างเดียว ( r ) หรือทั้งอ่านและเขียนได้ ( rw )
method:new RandomAccessFile ( path, mode );
return type:RandomAccessFile
content:ใช้สร้าง Object RandomAccessFile
example:String path_file = new String ( "C:/bamboo.txt" ); RandomAccessFile random_access_file = new RandomAccessFile ( path_file, "r" );
comment:mode คือกำหนดว่าอ่านได้อย่างเดียว ( r ) หรือทั้งอ่านและเขียนได้ ( rw )
method:close ();
return type:void
content:ใช้ปิดการทำงานของ Object RandomAccessFile
example:String path_file = new String ( "C:/bamboo.txt" ); RandomAccessFile random_access_file = new RandomAccessFile ( path_file, "r" ); random_access_file.close ();
method:length ();
return type:long
content:ใช้คืนค่า ขนาด ของ file ( หน่วย byte )
example:String path_file = new String ( "C:/bamboo.txt" ); RandomAccessFile random_access_file = new RandomAccessFile ( path_file, "r" ); long size_file = random_access_file.length ();
method:seek ( long_position );
return type:void
content:ใช้ เลื่อน pointer ไปยังตำแหน่งที่กำหนดใน file
example:String path_file = new String ( "C:/bamboo.txt" ); RandomAccessFile random_access_file = new RandomAccessFile ( path_file, "r" ); long size_file = random_access_file.length (); random_access_file.seek ( size_file / 2 );
method:skipBytes ( int_size );
return type:int
content:ใช้ ข้ามข้อมูลตามจำนวนที่กำหนด ใน file
example:String path_file = new String ( "C:/bamboo.txt" ); RandomAccessFile random_access_file = new RandomAccessFile ( path_file, "r" ); random_access_file.skipBytes ( 10 );
method:setLength ( long_size );
return type:void
content:ใช้กำหนด ขนาด สูงสุด ให้กับ file ( หน่วย byte )
example:String path_file = new String ( "C:/bamboo.txt" ); RandomAccessFile random_access_file = new RandomAccessFile ( path_file, "r" ); random_access_file.setLength ( 150 );
comment:ถ้าไฟล์มีขนาดเกินขนาดที่กำหนด แล้วข้อมูลตรงส่วนที่เกินจะถูกตัดทิ้งโดยอัตโนมัติ แต่ถ้าไฟล์มีขนาดน้อยกว่าขนาดที่กำหนด แล้วจะเกิดข้อมูลว่างจนทำให้ไฟล์มีขนาดตามที่กำหนด
method:read ();
return type:int
content:ใช้อ่านค่า ascii ของข้อมูล ณ ตำแหน่งปัจจุบันที่ pointer ชี้อยู่
example:String path_file = new String ( "C:/bamboo.txt" ); RandomAccessFile random_access_file = new RandomAccessFile ( path_file, "r" ); int buffer = random_access_file.read ();
method:readLine ();
return type:String
content:ใช้อ่านค่า ข้อมูล ครั้งละ 1 บรรทัด
example:String path_file = new String ( "C:/bamboo.txt" ); RandomAccessFile random_access_file = new RandomAccessFile ( path_file, "r" ); String data_line = random_access_file.readLine ();
method:write ( int_ascii );
return type:void
content:ใช้เขียนข้อมูล ลงไฟล์ โดยเขียนข้อมูลจากรหัส ascii ที่กำหนด
example:String path_file = new String ( "C:/bamboo.txt" ); RandomAccessFile random_access_file = new RandomAccessFile ( path_file, "r" ); random_access_file.write ( 65 );
method:writeChar ( int_ascii );
return type:void
content:ใช้เขียนข้อมูล ลงไฟล์ โดยเขียนข้อมูลจากรหัส ascii ที่กำหนด
example:String path_file = new String ( "C:/bamboo.txt" ); RandomAccessFile random_access_file = new RandomAccessFile ( path_file, "r" ); random_access_file.writeChar ( 65 );