문제

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.

도움이 되었습니까?

해결책

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...

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top