How to write a database to a text file in android

2019-03-20 15:41发布

I am working on a Spying application for my college project purpose. For that i have logged the Calls, Location and SMS of the device and stored them in a database. Now i want to export the contents of the database to a text file.. I tried the below code.

private void readAndWriteCallsData() {

    File dataBaseFile = getDatabasePath("DATABASE"); 

    File callDataFile = new File(Environment.getDataDirectory()+"/data/com.example.myapp/databases/"+"DATABASE");

    try {

        BufferedReader dbFileReader = new BufferedReader(new FileReader(callDataFile));

        String eachLine;

        while((eachLine = dbFileReader.readLine()) != null)
        {

                Callslog.append(eachLine);
                Callslog.append("\n");

        }

    } catch (IOException e) {

        e.printStackTrace();
    }


}

But that is not working... Please help me...

7条回答
劳资没心,怎么记你
2楼-- · 2019-03-20 16:48

One way to do this (I assume its a long procedure, easy one though), if you know the database and get all the tables and retrieve info from those tables. Since, we are talking about sqlite DBs, I assume it will be small.

SELECT * FROM dbname.sqlite_master WHERE type='table';
查看更多
登录 后发表回答