By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,798 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,798 IT Pros & Developers. It's quick & easy.

Read File strings

P: n/a
Dear All,
I am trying to open the file(walk5.dat) and then read the data
The structures of data are

0, 0, -10, -10, 0, -8.1,-12,-10 , 0,-14,-10,-7,0,
6.096666667,-10,-10,1, -1.118333333,-12,-10,1, -10.06666667,-10,-7,1

There are 25 data in one row and I want to read them and save them.
Each data is seperated by comma(,)

Basically I used readLine() command but I have an errer message like the
following,
"FunctionIntegratorTesterController.java": Warning #: 368 : method
readLine() in class java.io.DataInputStream has been deprecated at line 28,
column 28
I think readLine() command is old command.
If someone know the new command and have some advices, please let me know.
And I want to change the data structure where the data are seperated by
space. For example
0 0 -10 -10 0 ......
Right now I used StringTokenizer st = new StringTokenizer(data,",");
But I don't know how to change it for reading data which are seperated by
space.
I will appreciate too if you give some advice.
Thanks,
Jong
class FileOpen1
{
FileInputStream fis1;
DataInputStream dis1 ;
public void fileOpen()
{
try {
fis1 = new FileInputStream("walk5.dat");
dis1 = new DataInputStream(fis1);
}
catch(FileNotFoundException fe) {
System.err.println(fe);
}
}
public void fileData(double [] a)
{
String data = new String();
String [] dat = new String [25];
double [] data1 = new double [25];
try
{
data = dis1.readLine(); ********
}
catch(IOException f){ System.err.println(f);}
StringTokenizer st = new StringTokenizer(data,",");
for(int k=0;k<25;++k)
{
dat[k]=st.nextToken();
data1[k]=Double.parseDouble(dat[k].trim());
a[k]= data1[k];
}
}
}
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Jong Choi" <jx***@po.cwru.edu> wrote in message news:<bu**********@eeyore.INS.cwru.edu>...
Dear All,
I am trying to open the file(walk5.dat) and then read the data
The structures of data are

0, 0, -10, -10, 0, -8.1,-12,-10 , 0,-14,-10,-7,0,
6.096666667,-10,-10,1, -1.118333333,-12,-10,1, -10.06666667,-10,-7,1

There are 25 data in one row and I want to read them and save them.
Each data is seperated by comma(,)

Basically I used readLine() command but I have an errer message like the
following,
"FunctionIntegratorTesterController.java": Warning #: 368 : method
readLine() in class java.io.DataInputStream has been deprecated at line 28,
column 28
I think readLine() command is old command.
If someone know the new command and have some advices, please let me know.
And I want to change the data structure where the data are seperated by
space. For example
0 0 -10 -10 0 ......
Right now I used StringTokenizer st = new StringTokenizer(data,",");
But I don't know how to change it for reading data which are seperated by
space.
I will appreciate too if you give some advice.
Thanks,
Jong
class FileOpen1
{
FileInputStream fis1;
DataInputStream dis1 ;
public void fileOpen()
{
try {
fis1 = new FileInputStream("walk5.dat");
dis1 = new DataInputStream(fis1);
}
catch(FileNotFoundException fe) {
System.err.println(fe);
}
}
public void fileData(double [] a)
{
String data = new String();
String [] dat = new String [25];
double [] data1 = new double [25];
try
{
data = dis1.readLine(); ********
}
catch(IOException f){ System.err.println(f);}
StringTokenizer st = new StringTokenizer(data,",");
for(int k=0;k<25;++k)
{
dat[k]=st.nextToken();
data1[k]=Double.parseDouble(dat[k].trim());
a[k]= data1[k];
}
}
}


(1)Use BufferedReader which wrapps FileReader. Its readLine()
method is not deprecated.

(2)Space, Tab, Linefeed, Carriagereturn and Formfeed are
default delimiters for StringTokenizer. You don't need to
specify delimiters when you use them.
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.