Results 1 to 5 of 5
  1. #1
    Dukey is offline Member
    Join Date
    Apr 2009
    Posts
    2
    Rep Power
    0

    Default Reading In Text Files

    I'm having a real tough time reading in a text file. I'm using JCreater.

    Scanner sc = new Scanner(new File("test.txt"));

    I've tried putting test a bunch of places, but I always get

    unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown

    Any Ideas of whats going on? I have the test.txt file in my source folder and class folder.

  2. #2
    Dukey is offline Member
    Join Date
    Apr 2009
    Posts
    2
    Rep Power
    0

    Default

    Ah, all I needed was a throws Exception;

    Could someone explain to me what this does and why it is required?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Have a look at the source: Lesson: Exceptions (The Java™ Tutorials > Essential Classes)
    this will tell you what you need to know. Best of luck!

  4. #4
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    396
    Rep Power
    6

    Default

    You have to put your text file under the src folder of your project.
    Mak
    (Living @ Virtual World)

  5. #5
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

Similar Threads

  1. working with files (text files)
    By itaipee in forum New To Java
    Replies: 1
    Last Post: 02-24-2009, 11:38 AM
  2. Reading and Writing Text Files
    By kandt in forum New To Java
    Replies: 1
    Last Post: 11-12-2008, 03:15 AM
  3. Behaving text files like binary files
    By Farzaneh in forum New To Java
    Replies: 2
    Last Post: 08-27-2008, 03:20 PM
  4. Does OS intervene when reading Java text files
    By Tina G in forum Advanced Java
    Replies: 1
    Last Post: 04-07-2008, 02:29 PM
  5. Applet - reading text files packed into JAR file
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •