I am trying to import a database that I have stored on my SD card that I used as a backup to replace the current database if I want to revert back to something but when I try to import I get a NonWritableChannelException
error
12-15 12:27:48.190: W/System.err(13599): java.nio.channels.NonWritableChannelException
12-15 12:27:48.190: W/System.err(13599): at java.nio.FileChannelImpl.checkWritable(FileChannelImpl.java:85)
12-15 12:27:48.190: W/System.err(13599): at java.nio.FileChannelImpl.transferTo(FileChannelImpl.java:399)
12-15 12:27:48.190: W/System.err(13599): at com.tyczj.bowling.Bowlers$ImportData.importGames(Bowlers.java:944)
12-15 12:27:48.200: W/System.err(13599): at com.tyczj.bowling.Bowlers$ImportData.doInBackground(Bowlers.java:914)
12-15 12:27:48.200: W/System.err(13599): at com.tyczj.bowling.Bowlers$ImportData.doInBackground(Bowlers.java:1)
12-15 12:27:48.200: W/System.err(13599): at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-15 12:27:48.200: W/System.err(13599): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-15 12:27:48.210: W/System.err(13599): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-15 12:27:48.210: W/System.err(13599): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-15 12:27:48.210: W/System.err(13599): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-15 12:27:48.210: W/System.err(13599): at java.lang.Thread.run(Thread.java:856)
here is the method I use to import
public boolean importGames(){
File newDB = new File(Environment.getExternalStorageDirectory() + "/BCAData/Games");
File oldDB = new File(Environment.getDataDirectory()+"/data/my.app.package/databases/Games");
if(newDB.exists()){
try {
FileChannel fromChannel = new FileInputStream(newDB).getChannel();
FileChannel toChannel = new FileInputStream(oldDB).getChannel();
fromChannel.transferTo(0,fromChannel.size(),toChannel); //fails here
try{
if(fromChannel != null){
fromChannel.close();
}
}finally{
if(toChannel != null){
toChannel.close();
}
}
return true;
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
What does this error mean, I have never had this one before and how can I import the database file properly
Your “to” channel should be a File Output Stream, since you want to write into (not read from) this file: