Buffered writer in a .jar file
I am wondering if it is possible to place a buffered writer in a .jar file to create a .dat file for a high scores table. Can a .jar file edit a .dat file saved in with the classes? and if i can would every computer i play on have to have a jdk or could a computer without a jdk still edit the hiscore.dat file?
Re: Buffered writer in a .jar file
Are you trying to update the jar file that the code is executing from?
I'm not sure you can do that. The file to be updated needs to be outside of the jar file.
You do not need a JDK to execute a java program. You do need a JRE.
Re: Buffered writer in a .jar file
What im trying to do is say im playing a number puzzle and i win in 3 moves i want it to save my name, and number of moves. in a .dat file in the .jar file. and then have a seperate method that will read the .dat file and display them if called through most likely a menubar at the top. (i also want to sort them in order of 1st through 10th place) so say i used the buffered writer class would it write the .dat file. (not updating the whole file just the .dat file)
Re: Buffered writer in a .jar file
I'm not sure you can update the jar file while executing classes that are in that jar file.
Where else can you store your data so you can update it?
Re: Buffered writer in a .jar file
ok. so could i make it write to the directory location the .jar is at? and then have it called if certain menubutton is clicked. I.E. (c:\Users\"Name"\Documents). What im wanting to do is use a local computer as the main computer and have other players access that file from there computer(all on 1 network) and just rewrite the .dat file. (would that work) I have the working from 1 computer to the next working. and i can write from anycomputer on the network. Im just wondering if i can save the .dat file there and create a buffered writer to update the .dat file. (is there a get location type thing?) so i can make the computer find its location in the harddrive.(like if it is on the desktop it gets the filename for the desktop)
Re: Buffered writer in a .jar file
Quote:
have other players access that file from their computer
That sounds like a client connecting to a server.
The server has the .dat file on its local disk. The clients do their accesses to the file by making requests to the server.
Re: Buffered writer in a .jar file
kind of like a client and server. but its all in a local network. and if the jar file is moved from the location on the main computer it saves to the documents and becomes a (only 1 user) private hiscore table. (it wouldnt be on the web were u type in the html address and it loads. just when you double click the .jar file it opens and when u win the game it saves to the .dat file.
Re: Buffered writer in a .jar file
Are you talking about what MS calls UNC paths? (Uniform Naming Convention) that use \\ at the start?
The File class supports them and you can access the files just like files at any other path.
Read the API doc for the File class. It has examples.
Write a small test program on your computer that uses a UNC path in a File constructor and see how it works.
Re: Buffered writer in a .jar file
I looked it up and I think i can use that for what i want to do. I thanked your post.