Results 1 to 9 of 9
Thread: Update Text File
- 01-09-2009, 01:06 PM #1
Member
- Join Date
- Jan 2009
- Posts
- 4
- Rep Power
- 0
Update Text File
Hi,
I have been making a banking system in Java, at the moment I have been trying to get it to recorded certain values to a text document which I have done. I cant seem however to get it to update the text file instead of recreating it each time.
Src:
Java Code:import java.io.*; public class storage { public static void main(String[] args) throws IOException{ //Record Details Writer output = null; String accountnumber = "number"; String accountname = "name"; String accounttype = "Normal"; String accountbalance = "£39,000"; String accountstatus = "enabled"; File info = new File("accounts.txt"); output = new BufferedWriter(new FileWriter(info)); //Layout output.write(" |"); output.write(" "); output.write(accountnumber); output.write(" |"); output.write(" "); output.write(accountname); output.write(" |"); output.write(" "); output.write(accounttype); output.write(" |"); output.write(" "); output.write(accountbalance); output.write(" |"); output.write(" "); output.write(accountstatus); output.write(" |"); output.close(); System.out.println("File Written."); } }
- 01-09-2009, 01:13 PM #2
Member
- Join Date
- Dec 2008
- Location
- Italy
- Posts
- 79
- Rep Power
- 0
If I have understood you, then you should look at java.nio package
java.nio package
But I think you don't need that sophysticated feature....
- 01-09-2009, 01:24 PM #3
Member
- Join Date
- Jan 2009
- Posts
- 4
- Rep Power
- 0
all I need is some code to make it add a new line each time in the text document so every time it compiles it wont start a new file but just keep adding a line to the existing one.
- 01-09-2009, 01:47 PM #4
Member
- Join Date
- Dec 2008
- Location
- Italy
- Posts
- 79
- Rep Power
- 0
OK so all you need is a Reader to read your file in your program. THEN manipulate it and write it to disk with a Writer like you did
- 01-09-2009, 01:49 PM #5
Member
- Join Date
- Jan 2009
- Posts
- 4
- Rep Power
- 0
im not sure on the code for that, any chance you could give me an example?
Last edited by yuminstall; 01-09-2009 at 01:58 PM.
- 01-09-2009, 02:29 PM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
This sort of thing is perfect for RandomAccessFile (although I believe that is, probably, far too advanced for you).
- 01-09-2009, 02:52 PM #7
append?
Check to see if the file exists and if it does, use the append method instead of the write method.
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 01-09-2009, 03:01 PM #8
Member
- Join Date
- Jan 2009
- Posts
- 4
- Rep Power
- 0
yeah the file exists and has the information in it, how would i change the code so it would use the append method instead?
- 01-09-2009, 03:02 PM #9
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Similar Threads
-
using java dom to update file
By newbieal in forum New To JavaReplies: 6Last Post: 10-10-2008, 11:16 PM -
find and replace text from a text file
By gezzel in forum New To JavaReplies: 2Last Post: 09-19-2008, 04:04 PM -
[SOLVED] Update an XML file
By Eranga in forum Advanced JavaReplies: 4Last Post: 07-15-2008, 02:03 PM -
can i update the tag value of XMl file by other value(string
By pankaj_salwan in forum Advanced JavaReplies: 7Last Post: 07-04-2008, 08:12 AM -
Update a record in Random access file
By Rgfirefly24 in forum New To JavaReplies: 2Last Post: 04-24-2008, 10:07 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks