This site requires JavaScript, please enable it in your browser!
Greenfoot back
someone1
someone1 wrote ...

2015/10/15

Writing to a file

someone1 someone1

2015/10/15

#
Ok this is probably a nooby question but, I want the user to specify a particular file, from my game files which goes from games files 1 to 10, (Games1.txt,Games2.txt....Games10.txt) they then have to enter information into it which contains the following fields on one line(there is only one line in each text file but the information is repeated 3 times on the one line) stockNumber, RRP(must be of type int), retailPrice(must be an int)
danpost danpost

2015/10/15

#
What part of this are you having trouble with and what have you tried?
someone1 someone1

2015/10/15

#
Iam not sure how to implement this, i have tried using filewriter class to write to the specified file but with no sucess. Oh and i forgot to mention i only want to modify the RRP and retailPrice not stockno.
danpost danpost

2015/10/17

#
First thing: using 10 different files is not very efficient -- especially since you have a limited amount of data in each file. Better would be to have 10 records in one file. Each record could be parsed into its individual fields. A double array can be used to store the fields:
String[][] data = new String[10][3];
It does not matter what fields are modified -- just output the data for the entire file when needed. No help can be provided for outputting the file without your attempted code.
You need to login to post a reply.