0

I would like to make a xml file that will be modified during the execution of the application and i want to keep it after i close it for the next time i open it.

The first problem is that i don't know where do i have to put the file in the package explorer on Eclipse.

If i put the file on res/raw/ folder i could just read the file, but i can't modify.

I'm working with Jdom2. The file is a score table for a game that will be modified every time the player finish a game.

That's the code i actually have to read the xml file stored on res/raw

    try
    {
       puntf = getResources().openRawResource(R.raw.punt);

     } catch (Exception ex)
     {
        Log.e("Ficheros", "Error");
     }

And that's the code i actually have to modify the xml file(with Jdom2). But of course, that is wrong.

public void escritura()
{
  try 
  {     
        xmlOutput.output(puntu, new FileOutputStream("punt.xml"));
  } 
  catch (Exception e) {
        e.printStackTrace();
    }
}

Thanks a lot for your answers.

logame
  • 3
  • 4

2 Answers2

0

If you want to save a file and modify it programmatically I would suggest you to store it in this path:

/data/data/com.yourpackage.app/punt.xml

I have never worked with Jdom2, but you can have access to it by adding these lines of code:

File puntFile= new File("data/data/com.yourpackage.app/punt.xml");
FileOutputStream fos = new FileOutputStream(puntFile);
xmlOutput.output(puntu, fos);

You can also see the file in DDMS in file explorer. Just follow that path.

I can't understand if you want to save and edit the file during the process of your application or just save it somewhere before the app starts and edit it afterwords. If so, please give more details about that.

Hope I helped...

  • I want to edit the file during the process. It's a score table for a game. The problem is that i don't know where do i have to put the file on Eclipse package explorer! I mean, the file is already created. – logame Sep 15 '13 at 23:30
  • Ok I got it. You can save your file in the assets folder and the first time the application runs, you can copy it in the path that I suggested you above. You can see how to copy the file from the assets folder [here](http://stackoverflow.com/a/4530294/1407936). Just replace the path of the file that is created to the path I gave you. – Michael Bakogiannis Sep 16 '13 at 13:20
  • Thank you so much!! Finally i just made the changes you told me at first, but i will keep the info about assets. As i tried at first, i read the file inside Raw with jdom parser, i create an empty file with the same name in the folder you told me, and then i rewrite this empty file. Now i will try to make a method to know if the file is already created for just modify it next time i open the app. – logame Sep 16 '13 at 16:02
0

You should read uo on storage options on Andriod: THere's an article on this.... Use the resulting input and output streams for JDOM.

rolfl
  • 17,539
  • 7
  • 42
  • 76