473,399 Members | 3,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Saving and Loading Issues

Okay, so I have two methods, one to save selected arrow keys to a text file, and the other to load them as integers. Here's the first:

Expand|Select|Wrap|Line Numbers
  1. public void saveKeys()
  2. {
  3.    String out = Integer.toString(left)+"\n"+Integer.toString(right)+"\n"+Integer.toString(up)+"\n"+Integer.toString(down)+"\n";
  4.    try
  5.    {
  6.       PrintWriter save = new PrintWriter("key_selection.txt",out);
  7.    }
  8.    catch ( Exception e )
  9.    {
  10.             System.err.print(e);
  11.    }
  12. }
...which gives me this error message:

Expand|Select|Wrap|Line Numbers
  1. java.io.UnsupportedEncodingException: 37
  2. 39
  3. 38
  4. 40
  5.  
After inputting what it should have saved into the save file ("37\n39\n38\n40\n"), here is the code I made:

Expand|Select|Wrap|Line Numbers
  1. public void loadKeys()
  2. {
  3.    try
  4.    {
  5.       FileInputStream fis = new FileInputStream("key_selection.txt");
  6.       BufferedInputStream bis = new BufferedInputStream(fis);
  7.       String in = "";
  8.       while ( bis.read() > -1 )
  9.       {
  10.          in += (char)bis.read();
  11.       }
  12.       System.out.println(in);
  13.    }
  14.    catch ( Exception e )
  15.    {
  16.       System.err.println(e);
  17.    }
  18. }
...which gives me this as output:

Expand|Select|Wrap|Line Numbers
  1. 7
  2. 9
  3. 8
  4.  
  5.  
(There should be a zero on line 4, but I don't know why there isn't.)

What am I doing wrong? Please help!
Jul 24 '12 #1
0 1134

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Joe | last post by:
Hi Does anyone know of any issues about loading config files for windows forms applications? I have an application that utilizes a config file that holds my database connection string as well...
4
by: Jerivix Entadi | last post by:
I'm attempting to create an application to work with a fluid database of people. I'm doing this in a command line, text-based manner. I need to know two things: 1) How do I save data, perhaps a...
2
by: Bora | last post by:
Is there a resource that discusses how C++ objects are saved to and loaded from files? Sorry if this is not a strictly C++ issue. In particular, I am looking for information about maintaining...
2
by: Carl Gilbert | last post by:
Hi I have a function called GetXml that returns Xml as expected. I then use: Dim saveFile As New SaveFileDialog and the configure saveFile. Having got the file and the Xml, how can I then...
0
by: headware | last post by:
I've been reading about saving the state of the controls of a page so the user can be redirected to another page and then return to the original in the state it was in when they left. I've seen a...
2
by: Cary | last post by:
This may reveal my poor programming skills, but here goes... I'm building a pricing tool for my business. I'm nearing the end of the project, and I've been asked to be able to save quotes in some...
3
by: Peter Oliphant | last post by:
Trying to save/load a class instance to a file is tough. The reason is because there is no way to preserve its type other than by conventon. For eample, one can save all the states of the members...
0
by: MLM450 | last post by:
Does anybody know how to load a ToolStrip's location within a ToolStripPanel? I have several ToolStrips and want them to remember their location from one session to the next. I have tried saving...
6
by: Robm | last post by:
Since googling this issue only brings up the April fool's problem, which was solved years ago, I hope that somebody can help me with this. I have a large vc++/mfc application which needs to know...
7
mrnn
by: mrnn | last post by:
Ok I know how to save and load 1 variable from a file, but when it comes to loading multiple variables, I get confused. And all the articles I've found using Google and on here haven't helped too...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.