Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

Java Programming Tutorial - 81 - Reading from Files

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
71,169
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Oct 23, 2009

How to read data from a file

  • likes, 7 dislikes

Link to this comment:

Share to:

Top Comments

  • Another way to get file contents:

    while (x.hasNextLine()) System.out.println(x.nextLine(­));

  • great tutorial as expected. wondering if you're covering vectors also... but i think its all GUI from here

see all

All Comments (111)

Sign In or Sign Up now to post a comment!
  • I hear crickets in the background. Are you programming in the woods? Right on!

  • can you use this same method to read a Config file?

  • How can I open a file that i have created with Formatter to store more values???

  • My error (see my comment below) only occurs when I have only 1 number, 1 first name, and 1 last name. When I added more numbers and names to my file, it printed out the correct stuff.

  • I'm getting an error involving my readFile method:

    Exception in thread "main" java.util.NoSuchElementExcepti­on at java.util.Scanner.throwFor(Unk­nown Source) at java.util.Scanner.next(Unknown Source) at readfile.readFile(readfile.jav­a:24) --> This line is the declaration of c. at apples.main(apples.java:5) --> This line calls the method readFile.

  • @Tinzert

    int sum=0;

    while(x.hasNextInt){

    sum+=x.nextInt();

    }

  • @Tinzert Store it in a variable and then convert it to a int, make temp variables to add them!

  • My program NEVER writes, what's in the class. I tried many things but nothings working. can so help?

  • Say I read a number from a file -- how would I add those numbers together? I saved the read data as int variables but for some reason I get an error "unexpected type" when they should be treated as regular variables.

  • @nWANTED yes this is far better compared to hasNext() because you read the whole line it is not confusing is it like wen u print the whole line, println but i think hasNext() is good to cover first in tutorial. java must be having many methods to read a file i guess.

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more