Redian新闻
>
新手请教怎样在Java里读文本文件中的内容
avatar
新手请教怎样在Java里读文本文件中的内容# Java - 爪哇娇娃
c*y
1
比如
一行里是
1 3 -1
如果我要读到这个行的每个数,最方便的
操作是怎样。
还有,要输出到文本文件时如何规定格式之类的。
在c++ 里,俺一般用
sscanf,sprintf.
谢谢。
avatar
xt
2

Read line, then use StringTokenizer.
You can use OutputStream.print() I think.

【在 c**y 的大作中提到】
: 比如
: 一行里是
: 1 3 -1
: 如果我要读到这个行的每个数,最方便的
: 操作是怎样。
: 还有,要输出到文本文件时如何规定格式之类的。
: 在c++ 里,俺一般用
: sscanf,sprintf.
: 谢谢。

avatar
c*g
3
The way java does this is kind of complicated (actually
it is similar to c++ way with std io), you open a file
with an FileInputStream, then wrap the FileInputStream with
InputStreamReader to become a Reader, then wrap the
InputStreamReader to become a BufferedReader, then
use readLine(), finally parse out. Kao.

【在 c**y 的大作中提到】
: 比如
: 一行里是
: 1 3 -1
: 如果我要读到这个行的每个数,最方便的
: 操作是怎样。
: 还有,要输出到文本文件时如何规定格式之类的。
: 在c++ 里,俺一般用
: sscanf,sprintf.
: 谢谢。

avatar
c*s
4
in Java 5.0 (was called 1.5.0 before) you can use scanf/printf same as in c

【在 c**g 的大作中提到】
: The way java does this is kind of complicated (actually
: it is similar to c++ way with std io), you open a file
: with an FileInputStream, then wrap the FileInputStream with
: InputStreamReader to become a Reader, then wrap the
: InputStreamReader to become a BufferedReader, then
: use readLine(), finally parse out. Kao.

avatar
w*r
5
ft.... you guys are really die-hard C junkie!!!

【在 c******s 的大作中提到】
: in Java 5.0 (was called 1.5.0 before) you can use scanf/printf same as in c
avatar
c*y
6
3x

【在 c**g 的大作中提到】
: The way java does this is kind of complicated (actually
: it is similar to c++ way with std io), you open a file
: with an FileInputStream, then wrap the FileInputStream with
: InputStreamReader to become a Reader, then wrap the
: InputStreamReader to become a BufferedReader, then
: use readLine(), finally parse out. Kao.

avatar
c*g
7
Actually I do appreciate the elegent (or elephant?) way of Java io
to read a file after couples of year java coding. But it does look
so stupid for first time user, hehe.

【在 w*r 的大作中提到】
: ft.... you guys are really die-hard C junkie!!!
avatar
w*r
8
their IO interface is very elegent, clear-cut and highly flexible.

【在 c**g 的大作中提到】
: Actually I do appreciate the elegent (or elephant?) way of Java io
: to read a file after couples of year java coding. But it does look
: so stupid for first time user, hehe.

avatar
m*t
9

FileReader would lend a little convenience here.

【在 c**g 的大作中提到】
: The way java does this is kind of complicated (actually
: it is similar to c++ way with std io), you open a file
: with an FileInputStream, then wrap the FileInputStream with
: InputStreamReader to become a Reader, then wrap the
: InputStreamReader to become a BufferedReader, then
: use readLine(), finally parse out. Kao.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。