• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Reading a file and Performing operation on the file.

 
Ranch Hand
Posts: 98
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Am working on an assignment which requires me to read from a file and count the number of items in each line.
I have read the file but I do not know how to print its content on to the console and then probably loop through it to count the number of items in the file.
Am suppose to use a library called TextIO.java which I have attached and the file am supposed to read from.

I will be glad if I can get some assistance here.
Thank you.

This is what I have done for far.

 
Sheriff
Posts: 6456
172
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not familiar with the TextIO package, but I'm sure you have to "open" the file first (I don't know the Java term for this, create a file handle?).  
 
Kelvin Okornoe
Ranch Hand
Posts: 98
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wasn't able to attach these files in my first post, here is a link to it.

link to the java library and file
 
Marshal
Posts: 66639
251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
People won't want to open unfamiliar wesites.

Don't know. I presume that TextIO allows you to read lines. You would have something likeThere ought to be instructions for reading with the TextIO package.
 
Kelvin Okornoe
Ranch Hand
Posts: 98
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:People won't want to open unfamiliar wesites.

Don'tt know. I presume that TextIO allows you to read lines. You would have something likeThere ought to be instructions for reading with the TextIO package.



Thank you Campbell for the response,

That link goes into my sharable google drive, where the TextIO package is located.

Going through the package I have not seen a method that allows me to read line, the best one have seen is the readFile method which is a static method too.

 
Kelvin Okornoe
Ranch Hand
Posts: 98
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Kelvin Okornoe wrote:I wasn't able to attach these files in my first post, here is a link to it.

link to the java library and file



Please this is a shareable link to my google drive, where the necessary TextIO.java file is located
 
Campbell Ritchie
Marshal
Posts: 66639
251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are there any instructions with the TextIO files? Is there a TextIO.html file anywhere (documentation comments)? Have you been told how TextIO works? What does the readFile() method return?
 
Kelvin Okornoe
Ranch Hand
Posts: 98
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Are there any instructions with the TextIO files? Is there a TextIO.html file anywhere (documentation comments)? Have you been told how TextIO works? What does the readFile() method return?



The file is actually TextIO.java, it has comments within it, I do not know of any html document that has a documentation of it...
readFile returns void

We have not been told how the TextIO.java works
 
Kelvin Okornoe
Ranch Hand
Posts: 98
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, some one has helped me with it...

Thank you for the effort,
 
Campbell Ritchie
Marshal
Posts: 66639
251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and what was the solution?
 
Kelvin Okornoe
Ranch Hand
Posts: 98
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:...and what was the solution?





This is a code snippet of the solution,  the getln() counts the words in the file
 
Bartender
Posts: 3674
151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is documentation of TextIO from the author of this class (D. J. Eck). See section 2.4.2 & 2.4.3
TextIO API
 
Kelvin Okornoe
Ranch Hand
Posts: 98
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Piet Souris wrote:Here is documentation of TextIO from the author of this class (D. J. Eck). See section 2.4.2 & 2.4.3
TextIO API


Thank you
 
Campbell Ritchie
Marshal
Posts: 66639
251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Piet Souris wrote:Here is documentation of TextIO . . .

Well done finding that It looks like my KeyboardInputs class. I am surprised that OP wasn't given that link with the instructions to use TextIO.
 
Piet Souris
Bartender
Posts: 3674
151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I started with java. I was looking for some text that could make me a bit wiser. I found this JavaNotes. It was version 6 then, but I learned a lot from it. I just noticed that version 8.1 now uses JavaFX instead of Swing, so a reason to have another look!
 
Kelvin Okornoe
Ranch Hand
Posts: 98
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Piet Souris wrote:When I started with java. I was looking for some text that could make me a bit wiser. I found this JavaNotes. It was version 6 then, but I learned a lot from it. I just noticed that version 8.1 now uses JavaFX instead of Swing, so a reason to have another look!



You did not provide a link to the note, I may want to look at it too
Thank you
 
Piet Souris
Bartender
Posts: 3674
151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Kelvin,

the link IS a link to the book, the page is just section 4 of chapter 2. There is a link on that page to go to the start. There you can also download a PDF version, all free of charge! The author also has links to other interesting books. Recommended!
 
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!