• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

gettin error with TextReader

 
neha gautam
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all..

here is the code i m tryin to execute its givin me the error with TextReader..
i can figure why..



the error is:



C:\neha>javac WordCount.java
WordCount.java:20: cannot find symbol
symbol : class TextReader
location: class WordCount
static TextReader in; // An input stream for reading the input file.
^
WordCount.java:137: cannot find symbol
symbol : class TextReader
location: class WordCount
static void readWords(TextReader inStream, Map words) {
^
WordCount.java:121: cannot find symbol
symbol : class TextReader
location: class WordCount
in = new TextReader(new FileReader(args[0]));
^
WordCount.java:176: package TextReader does not exist
catch (TextReader.Error e) {
^
Note: WordCount.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors



i don know what i m missin.....
please help..
thanks to all
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Neha,

TextReader is not standard Java API packaged in JDK. I guess you are trying to use JSci.io.TextReader or your own TextReader class ? anyways you got import it .

Add the jsci jar and import TextReader in the java.
 
neha gautam
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks balu......

ill try that out
 
neha gautam
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
even by importin its givin same error on compliation
i jus appended the progrm with:

import java.JSci.io.TextReader;


do i need to anyother thing except this
actually i hv to read my text file word by word
can you guys suggest some other way for the same.
thanks to all
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


import java.JSci.io.TextReader;


Like i mentioned earlier , we don't have any idea of which TextReader Class you are using. I guessed it as "JSci.io.TextReader" and you used "java.JSci.io.TextReader" , where java comes from.


actually i hv to read my text file word by word
can you guys suggest some other way for the same.


I can think of RandomAccessFile which can read line by line. Does that suffice ?
 
neha gautam
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for the response balu..

textreader is not my own class but java predefined input stream..
i have read the file word by word,,,,
and not line by line...
its like the text file of the form

0.300, -124.87,
0.362, -127.36,
0.425, -129.30,
0.487, -131.52,
0.549, -133.48,
0.612, -135.43,
0.674, -137.19,
0.736, -138.74,
0.798, -140.21,
0.861, -141.52,
0.923, -142.71,
0.985, -143.86,
1.048, -144.94,
1.110, -146.01,
1.172, -146.87,
1.235, -147.60,
1.297, -148.74,
1.359, -149.45,
1.422, -150.16,
1.484, -151.03,
1.546, -151.56,
1.609, -152.31,
1.671, -152.99,
1.733, -153.76,
1.796, -154.51,
1.858, -155.06,


and my job is to read the file and display a graph between the 1st and 2nd colmns
as X and Y axis, i have my graph prgm, jus had prblm in readin the contents..
so i thought the option of reading the file word by word and storin the colmnsin separate arrays and linkin
them with graph prgrams..
kindly correct me if you think i m wrong somewhr..
thanks for all your help
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


and my job is to read the file and display a graph between the 1st and 2nd colmns
as X and Y axis, i have my graph prgm, jus had prblm in readin the contents..


You could still use RandomAccessFile readLine() method() and could use StringTokenizer or spilt() method with delimiter as "space" or "comma". This way you could get word by word and store in arrays or other preferred approach you are after.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Balu Sadhasivam wrote:You could still use RandomAccessFile readLine()

RandomAccessFile really isn't the right class to use here; it's meant for circumstances that have no bearing on this case. A BufferedReader combined with a FileReader would be much more appropriate.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


A BufferedReader combined with a FileReader would be much more appropriate.


Yes, as long it has readLine() to read it easily.
 
jennifer pandian
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey neha.. I am working on a program similar to yours.. did you happen to correct your previous errors? if so, could you please post the corrected program ? It would be very useful to me.. Thanks
 
Surinder Mehra
Ranch Hand
Posts: 34
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is probably too late to post an answer. But still for future if required, We can read this file using Scanner and split the line by comma and store the two columns into two lists. Sample is given below:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic