android 拷贝DB数据到内存卡
<p>Android 拷贝DB 到内存卡</p>
<pre><code class="language-java"> /**
* 拷贝数据库到sd卡
*
* @deprecated &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;/&gt;
*/
public static void copyDatabaseToSd(){
if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
return ;
}
File dbFile = new File(MvpApplication.getApplication().getDatabasePath(&quot;penny&quot;)+&quot;.db&quot;) ;
File file = new File(Environment.getExternalStorageDirectory()+&quot;seeker.db&quot;) ;
FileChannel inChannel = null ;
FileChannel outChannel = null ;
try {
file.createNewFile() ;
inChannel = new FileInputStream(dbFile).getChannel() ;
outChannel = new FileOutputStream(file).getChannel() ;
inChannel.transferTo(0, inChannel.size(), outChannel) ;
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
if (inChannel !=null ) {
inChannel.close();
inChannel = null ;
}
if (outChannel != null ) {
outChannel.close();
outChannel = null ;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}</code></pre>