• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

gettin error with TextReader

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks balu......

ill try that out
 
neha gautam
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 44
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey neha will you please tell how you imported it and how you remove that TextIO, TextReader error
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

NG hasn't posted since this thread back in 2009, so you will probably not get an answer from him. I am afraid SM's suggestion is poor quality since he neither opened nor closed the Scanner correctly, and it appears to be using parallel Lists, a design just as dubious as parallel arrays.
I suggest you use a Scanner to read the file, or a BufferedReader via the lines() method, or one of its analogues:-You don't have to change the delimiter; you can use other ways to split the line if you prefer. I am not at all sure I have got that regular expression anywhere near correct.Files#lines() method.
Stream#map() method: this takes an input Stream and uses a function to convert that to a Stream<Foo>. I am assuming (deciding!) that Foo has a constructor taking a String of the same format as that in the file. You can read about the strange‑looking syntax with :: in the Java™ Tutorials.
The name should make it obvious what sort of Collector Collectors#toList() provides.
 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic