nirasan's tech blog

趣味や仕事の覚え書きです。Linux, Perl, PHP, Ruby, Javascript, Android, Cocos2d-x, Unity などに興味があります。

Androidでassetsのファイルをローカルストレージにコピー

  • assets/row.txt を /data/data/com.example/files/row.txt として保存する
try {
    InputStream inputStream = getAssets().open("row.txt");
    FileOutputStream fileOutputStream = openFileOutput("row.txt", MODE_PRIVATE);
    byte[] buffer = new byte[1024];  
    int length = 0; 
    while ((length = inputStream.read(buffer)) >= 0) {
        fileOutputStream.write(buffer, 0, length);
    }
    fileOutputStream.close();
    inputStream.close();
} catch (IOException e) {
    e.printStackTrace();
}