package text;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
/**
* @author Admin
* 实现文本的追加
*/
public class AppletText {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
RandomAccessFile raf = new RandomAccessFile("d://temp//1.txt","rw") ;
for(int i=0;i<10;i++) {
raf.writeUTF("this is a line你好你好" + i +"/n") ;//追加10行
}
raf.close() ;
int i = 0 ;
String record = new String() ;
RandomAccessFile raf2 = new RandomAccessFile("d://temp//1.txt","rw") ;
raf2.seek(raf2.length()) ;
raf2.writeBytes("append a line "+"/n") ;//追加一行
raf2.close() ;
RandomAccessFile raf3 = new RandomAccessFile("d://temp//1.txt","rw") ;
while((record =raf3.readLine())!= null) {
byte[] str = record.getBytes("ISO_8859_1") ;
String value = new String(str,"UTF-8") ;
i++ ;
System.out.println("Value"+ i+":"+value);//输出
}
raf3.close() ;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}