如题,这个应该并不是很难,难的是如果中文和外文混合的话不知道怎么读出,我的代码只能实现英文读出,如果中文和外文混杂的话就会读出乱码。如果某年某月某日某时你看到了这篇文章,并且可以处理现存的多种文字的话请在下面留言,多谢……
Code:
import java.io.*;
import java.util.*;
public class TestRandomAccessFile {
public static final void main(String[] args) {
try {
File f = new File("exp.txt");
if(!f.exists()) {
f.createNewFile();
}
RandomAccessFile raf = new RandomAccessFile(f,"rw");
String str = new String();
str = new Scanner(System.in).next();
for(int i=0; i
raf.write(str.charAt(i));
}
raf.writeUTF(str);
long len = str.length();
while(0 != len--) {
raf.seek(len);
char ch = (char)raf.read();
System.out.println(ch);
}
raf.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
标签: