Hi all wonder if someone could give me a bit of help, i'm new to using RnadomAccessFiles, so please bear with me. Basically i have the method below, which writes some data into a xml file, what i want to be able to do, is move the file pointer to back 1 each time. So in other words, each time the method is called, it will delete the last line of the previous entry.

So each time the method is called it will produce the following output:

<?xml version="1.0" encoding="UTF-8"?>
<playerName>Default Player</playerName>
<playerTime>null minutes null seconds</playerTime>

What i want to be able to do is delete "</indianaTuxPlayers>" each time the method is called and then write the rest of the data.

public void writeData(){
		 try {
		RandomAccessFile raf = new RandomAccessFile("test.xml", "rw");

	            String text[] = new String[2];
	            text[0] = "<?xml version='1.0' encoding='UTF-8'?>";
	            text[1] = "<indianaTuxPlayers> + '\n'";

	            for (int i = 0; i < text.length; i++) {

	            // Write another data at the end of the file.
		        raf.writeUTF("\t" + "<player>" + "\n");
		        raf.writeUTF("\t" + "\t" + "<playerName>" + playerName + "</playerName>" + "\n");
		        raf.writeUTF("\t" + "\t" + "<playerScore>" + pointCount + "</playerScore>" + "\n");
		        raf.writeUTF("\t" + "\t" + "<playerTime>" + minutes + " minutes " + seconds + " seconds" + "</playerTime>" + "\n");
		        raf.writeUTF("\t" + "</player>" + "\n");
		        raf.writeUTF("</indianaTuxPlayers>" + "\n");

	            // Move the file pointer to the beginning of the file
		    } catch (IOException e) {}
This article has been dead for over six months. Start a new discussion instead.