c**y 发帖数: 127 | 1 比如
一行里是
1 3 -1
如果我要读到这个行的每个数,最方便的
操作是怎样。
还有,要输出到文本文件时如何规定格式之类的。
在c++ 里,俺一般用
sscanf,sprintf.
谢谢。 |
xt 发帖数: 17532 | 2
Read line, then use StringTokenizer.
You can use OutputStream.print() I think.
【在 c**y 的大作中提到】 : 比如 : 一行里是 : 1 3 -1 : 如果我要读到这个行的每个数,最方便的 : 操作是怎样。 : 还有,要输出到文本文件时如何规定格式之类的。 : 在c++ 里,俺一般用 : sscanf,sprintf. : 谢谢。
|
c**g 发帖数: 274 | 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. : 谢谢。
|
c******s 发帖数: 8 | 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.
|
w*r 发帖数: 2421 | 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
|
c**y 发帖数: 127 | 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.
|
c**g 发帖数: 274 | 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!!!
|
w*r 发帖数: 2421 | 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.
|
m******t 发帖数: 2416 | 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.
|