Results 1 to 4 of 4
  1. #1
    Wolfsy is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default Reading in a file

    I do not get why this code doesnt work:



    import java.util.Random;

    public class Highscore{

    public int setHighscore; //setter needs to be private
    protected int getHighscore;
    public IOException;

    public Highscore(int setHighscore, int getHighscore){
    this.setHighscore = setHighscore;
    this.getHighscore = getHighscore;
    }

    public void setHighscore(int Highscore){
    }

    public Highscore() throws IOException {
    getHighscoreFromFile();
    }

    private void getHighscoreFromFile() throws IOException {
    FileReader input = new FileReader("highscore.txt");
    BufferedReader file = new BufferedReader(input);
    }
    }



    All I want to do is read in a file but it is saying that there is something wrong with the IOException?!

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default Re: Reading in a file

    If you want help, you'll have to provide an SSCCE as well as the full stack trace of the error, including the line it occurs on. Where is the file located? Where does your relative path point to? Create a File instance there and print out its absolute path if you aren't sure.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Reading in a file

    Indeed, does it compile?
    If not, what is the full text of the compilation error?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Reading in a file

    I believe this line that cause you an error:

    Java Code:
    public IOException;

Similar Threads

  1. Reading file external to jar file
    By nn12 in forum New To Java
    Replies: 6
    Last Post: 02-04-2011, 06:46 AM
  2. help regarding reading file in JSf
    By tajinder in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 09-13-2010, 05:25 PM
  3. reading a file and writing to a file....help!!!!
    By java_prgr in forum New To Java
    Replies: 3
    Last Post: 07-26-2010, 07:53 PM
  4. Replies: 9
    Last Post: 10-20-2009, 11:52 AM
  5. Replies: 3
    Last Post: 05-10-2009, 12:31 AM

Tags for this Thread

Posting Permissions

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