如题,这个应该并不是很难,难的是如果中文和外文混合的话不知道怎么读出,我的代码只能实现英文读出,如果中文和外文混杂的话就会读出乱码。如果某年某月某日某时你看到了这篇文章,并且可以处理现存的多种文字的话请在下面留言,多谢……
- importjava.io.*;
- importjava.util.*;
- publicclassTestRandomAccessFile{
- publicstaticfinalvoidmain(String[]args){
- try{
- Filef=newFile("exp.txt");
- if(!f.exists()){
- f.createNewFile();
- }
- RandomAccessFileraf=newRandomAccessFile(f,"rw");
- Stringstr=newString();
- str=newScanner(System.in).next();
- for(inti=0;i<str.length();i++){
- raf.write(str.charAt(i));
- }
- raf.writeUTF(str);
- longlen=str.length();
- while(0!=len--){
- raf.seek(len);
- charch=(char)raf.read();
- System.out.println(ch);
- }
- raf.close();
- }catch(IOExceptione){
- e.printStackTrace();
- }
- }
- }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。