Android

个人Android学习总结


android 拷贝DB数据到内存卡

<p>Android 拷贝DB 到内存卡</p> <pre><code class="language-java"> /** * 拷贝数据库到sd卡 * * @deprecated &amp;lt;uses-permission android:name=&amp;quot;android.permission.WRITE_EXTERNAL_STORAGE&amp;quot;/&amp;gt; */ public static void copyDatabaseToSd(){ if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { return ; } File dbFile = new File(MvpApplication.getApplication().getDatabasePath(&amp;quot;penny&amp;quot;)+&amp;quot;.db&amp;quot;) ; File file = new File(Environment.getExternalStorageDirectory()+&amp;quot;seeker.db&amp;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>

页面列表

ITEM_HTML