由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - java可以直接去读txt file里指定的一行吗?
相关主题
初学java的书Java版BBS之设想
从文件读入数据得到的是bytes网页的Form中Post的问题 (转载)
这段实例化的代码可以优化提速吗?File generated by Java cannot be read by Android App
再请问版主一个随机读取文件的问题C++ JNI code to invoke native method – header an (转载)
一个 skip list 面试题java image processing problem
问一个关于pdf的问题请教关于java文件操作
为啥logger.info print 出来的时间超前?Re: 文件读入的问题
如何避免java web start读取资源文件读了多次新手问一个弱问题, 关于从stdin输入int或者其他数值的实现方法
相关话题的讨论汇总
话题: line话题: java话题: bytes话题: so话题: file
进入Java版参与讨论
1 (共1页)
b*********n
发帖数: 1258
1
请问
java 里可以直接去读 txt file 里指定的第 n 行
而不经过读入前 n-1 行吗?
谢谢
s******n
发帖数: 876
2
no...

【在 b*********n 的大作中提到】
: 请问
: java 里可以直接去读 txt file 里指定的第 n 行
: 而不经过读入前 n-1 行吗?
: 谢谢

S********a
发帖数: 1163
3
no way. u might be able to skip, but java still needs to read to skip

【在 b*********n 的大作中提到】
: 请问
: java 里可以直接去读 txt file 里指定的第 n 行
: 而不经过读入前 n-1 行吗?
: 谢谢

g*****g
发帖数: 34805
4
There's no line concept in a file. Line is
determined by line separator. So you have to read
every character to know if this is a new line.
You can't do this in any language.
You can however, skip certain bytes without reading.

【在 b*********n 的大作中提到】
: 请问
: java 里可以直接去读 txt file 里指定的第 n 行
: 而不经过读入前 n-1 行吗?
: 谢谢

A**o
发帖数: 1550
5
不可以跳过,但是可以用buffer reader去读。

【在 b*********n 的大作中提到】
: 请问
: java 里可以直接去读 txt file 里指定的第 n 行
: 而不经过读入前 n-1 行吗?
: 谢谢

b*********n
发帖数: 1258
6
Thanks.
So which means, without knowing how many bytes are ahead of the n line,
there's no way for you to directly read the n line?
one more question,
let's say if I know there are m bytes ahead of the n line,
and try to skip,
does that mean the time consumed in reading the previous m bytes can be
skipped as well?
Thanks!

【在 g*****g 的大作中提到】
: There's no line concept in a file. Line is
: determined by line separator. So you have to read
: every character to know if this is a new line.
: You can't do this in any language.
: You can however, skip certain bytes without reading.

t***e
发帖数: 3601
7
Try randomaccessfile. but again, you don't know where is the line untill you
read it.
g*****g
发帖数: 34805
8

right
yes

【在 b*********n 的大作中提到】
: Thanks.
: So which means, without knowing how many bytes are ahead of the n line,
: there's no way for you to directly read the n line?
: one more question,
: let's say if I know there are m bytes ahead of the n line,
: and try to skip,
: does that mean the time consumed in reading the previous m bytes can be
: skipped as well?
: Thanks!

w*****d
发帖数: 2415
9
Java handles input/output using (Data/Object)Input/OutPutStream. So thinks
about I/O as bit stream, Java has to read from the beginning to determine
the content, remember, text files' lines are separated by line separator and
there is no way for Java to know which is the nth line until it reads in
bit by bit.
From the implementation point of view, unless the length of each line is
fixed or header information containing each line's location is stored (plain
text file doesn't have header though),

【在 b*********n 的大作中提到】
: Thanks.
: So which means, without knowing how many bytes are ahead of the n line,
: there's no way for you to directly read the n line?
: one more question,
: let's say if I know there are m bytes ahead of the n line,
: and try to skip,
: does that mean the time consumed in reading the previous m bytes can be
: skipped as well?
: Thanks!

h******e
发帖数: 150
10
如果是固定行长度文件,可以直接跳
这东西和JAVA没什么关系把.用C/C++都是一样的弄.
1 (共1页)
进入Java版参与讨论
相关主题
新手问一个弱问题, 关于从stdin输入int或者其他数值的实现方法一个 skip list 面试题
A question about how to segment intput text file问一个关于pdf的问题
想给程序加个最简单的窗口界面,请帮忙为啥logger.info print 出来的时间超前?
java 里可以插入linux command吗?如何避免java web start读取资源文件读了多次
初学java的书Java版BBS之设想
从文件读入数据得到的是bytes网页的Form中Post的问题 (转载)
这段实例化的代码可以优化提速吗?File generated by Java cannot be read by Android App
再请问版主一个随机读取文件的问题C++ JNI code to invoke native method – header an (转载)
相关话题的讨论汇总
话题: line话题: java话题: bytes话题: so话题: file