Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8980759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:09:59+00:00 2026-06-15T20:09:59+00:00

I have a problem with a file saving alogrithm. error: dec 11, 2012 4:56:18

  • 0

I have a problem with a file saving alogrithm.

error:
dec 11, 2012 4:56:18 PM tetris.FileIO loadHighscores
SEVERE: null
java.io.FileNotFoundException: file:\C:\Users\Koen\Dropbox\2TI\vgo\Eindwerk\Tetris\build\classes\tetris\LineHighscores.txt (De syntaxis van de bestandsnaam, mapnaam of volumenaam is onjuist)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at java.util.Scanner.<init>(Scanner.java:656)
    at tetris.FileIO.loadHighscores(FileIO.java:44)
    at tetris.FileIO.getLineScores(FileIO.java:31)
    at tetris.FileIO.main(FileIO.java:69)

Exception in thread "main" java.lang.NullPointerException
    at tetris.FileIO.loadHighscores(FileIO.java:49)
    at tetris.FileIO.getLineScores(FileIO.java:31)
    at tetris.FileIO.main(FileIO.java:69)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

idk what is wrong, this is a saveing algorithm for a small tetris game.

The files are saved under :

...\Eindwerk\Tetris\build\classes\tetris\LineHighscore.txt
...\Eindwerk\Tetris\build\classes\tetris\TimeHighscore.txt

I’ve added a main class to this class.
paste it into your ide and run it, i get many errors

public class FileIO   {
    private File file;
    private Scanner filescScanner, lineScanner;
    private Writer fileWriter, lineWriter;
    private String[][] data;


    public FileIO () {
        String[][] data = new String[100][1];
    }
    public String[][] getLineScores(){
        return this.loadHighscores(this.getClass().getResource("LineHighscores.txt").toString());
    }
    public String[][] getTimeScores(){
        return this.loadHighscores(this.getClass().getResource("TimeHighscores.txt").toString());
    }

    public String[][] loadHighscores(String path){
        int x=0;
        String test = "";
        file = new File(path);

        try {
            filescScanner = new Scanner(file);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(FileIO.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.out.println(file.toString());
        while((test=filescScanner.nextLine())!=null) {

            lineScanner = new Scanner(test);
            lineScanner.useDelimiter("-/-");
            System.out.println(lineScanner);
            System.out.println(lineScanner.toString());
            data[x][0]=lineScanner.next();//name    
            data[x][1]=lineScanner.next();//data   
            x++;

        }
        lineScanner.close();
        filescScanner.close();
        return data;

    }


    public static void main(String[] args){
        FileIO file = new FileIO();
        System.out.println(file.getLineScores());


    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:10:01+00:00Added an answer on June 15, 2026 at 8:10 pm

    The issue is that you are not passing a valid path to new File. this.getClass().getResource("LineHighscores.txt") returns a URL object. You’re then getting a String representation of the URL object.

    But when calling new File(String), the constructor expects a path name, not a String containing a file:// URL. Since “file:\C:\Users\Koen\Dropbox\2TI\vgo\Eindwerk\Tetris\build\classes\tetris\LineHighscores.txt” is not a valid Windows path name, an exception is thrown.

    There are a few ways to address this. An easy method would be to use getResourceAsStream instead of getResource().toString(). Then change

    public String[][] loadHighscores(String path){
        int x=0;
        String test = "";
        file = new File(path);
    
        try {
            filescScanner = new Scanner(file);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(FileIO.class.getName()).log(Level.SEVERE, null, ex);
        }
    

    to

    public String[][] loadHighscores(InputStream resourceStream){
        int x=0;
        String test = "";
    
        filescScanner = new Scanner(resourceStream);
    

    This will allow you to read directly from the input files. And loadHighScores no longer cares whether the data is coming from an actual File, or another location. This can be handy if you ever need to read from a resource within a jar file on the classpath. You won’t be able to read it directly as a file, but using getResourceAsStream can give you the content.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with saving the path in doctrine from a file upload.
I seem to have stumbled over a problem regarding saving an xml file from
i'm saving/retrieving data from a plist file but i have a problem, i can't
I have problem with saving MJPEG stream to file. When I stream MJPEG using
I have problem for bulk insert of the file.I am saving the multiple record
I become use raw socket and i have this problem: bad file descriptor the
I have problem with copying sdf file to WM emulator. My solution structure MyApp.DataLayer
I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
I have a problem downloading particular file types by WebClient. So there are no
I have a problem to Store file (from a remote API) in MongoDB, i'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.