留言与评论(共有 0 条评论) |
发布时间:2020-04-12 09:12:38
用程序语言先实现按行读取,获取每一行的hello world个数
另外使用文件随机读取编程(建议用java或c实现),使读取指针可以移至下一行
public void readFileByRandomAccess2(String fileName) throws Exception {
File file=new File(fileName);
if(!file.exists()){
throw new Exception("文件不存在");
}
String search_file_name="assets/search/search_"+file.getName();
RandomAccessFile randomFile = null;
try {
System.out.println("随机读取一段文件内容:");
// 打开一个随机访问文件流,按只读方式
randomFile = new RandomAccessFile(file, "r");
// 文件长度,字节数
long fileLength = randomFile.length();
long test_fileLength =0;
if (fileLength <= 0) {
return;
}
System.out.println("文件总长度:"+fileLength);
// 读文件的起始位置
int beginIndex = 0;
// 将读文件的开始位置移到beginIndex位置。
randomFile.seek(beginIndex);
String line;
byte[] bytes = new byte[1024];
ByteArrayOutputStream bytearray=new ByteArrayOutputStream();
this.filePutContents(search_file_name, "
留言与评论(共有 0 条评论) |
全站搜索