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 9061811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:34:50+00:00 2026-06-16T15:34:50+00:00

I have made a java applet/application game that should save levels that the user

  • 0

I have made a java applet/application game that should save levels that the user can create to their local machine.
I say applet/application because it can run either as an application or as an applet.
Currently I am using this to write the file:

BufferedWriter bf = new BufferedWriter(new FileWriter("Circles/levels/level.txt"));
for (int i = 0; i < lines.size(); i++) {
    bf.write(lines.get(i));
    bf.newLine();
}

lines is an arraylist with the lines to write to the file.

and

FileReader fr = new FileReader("Circles/levels/level.txt");
        BufferedReader bf = new BufferedReader(fr);
        lines = new ArrayList<String>();
        while (true) {
            String line = bf.readLine();
            if (line == null) {
                break;
            }
            lines.add(line);
        }
        bf.close();

to read the file. Those are surrounded in try/catch loops, I am just showing what I have to.

This works ok, but it seems to be a completely different location on different operating systems, and the application stores in a different location as the applet.

I would like a way to get an absolute path to a place to save levels that would not change no matter where the java program is being run from, and would be the same if you ran it as an application and as an applet. Also it would be nice to have this work on all operating systems (linux, windows, mac).

  • 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-16T15:34:52+00:00Added an answer on June 16, 2026 at 3:34 pm

    There is no location at all for applets to save data, so if you want to be running as an applet, you have to avoid that, quite simply. The applet sandbox prevents filesystem access completely. You’d need to call on the server to save your data instead.

    As for stand-alone applications, I’m also sorry to say that there is no completely generally acceptable convention. However, creating a dotfile directory in the user’s home directory is often considered acceptable practice on both Linux, OSX and Windows:

    public static final File savedir = new File(new File(System.getProperty("user.home")), ".yourgame");
    

    Then, derive your filenames from that:

    FileReader fr = new FileReader(new File(savedir, "level.txt"));
    

    Although it works, it’s not exactly what Windows programs would normally do, however.

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

Sidebar

Related Questions

I have made a Java EE 6 application where a user can browse a
I have made a java application that stores data from a .csv file to
I have made a Java Applet that depends on some third party libriaries as
I have read that generally abstract classes should not be made Serializable in Java.
I made a java application that saves data to a .data file. I have
When running a java applet that I made (a basic little number-guessing game), whenever
I have made a Java application with Java 1.7 my problem is that it
I have made a small java swing application that I want to share with
I have a java application that I made and this week I tried to
I have made a java application and have packed it into an executable jar

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.