public boolean readFilefromAssets(Context context, String assetsFile){
InputStream stream = assets.open(assetsFile)
if (stream == null) {
Toast.makeText(context, "assets no such file", Toast.LENGTH_SHORT)
.show()
return false
}
String folder = File.separator + "mnt" + File.separator + "sdcard"
+ File.separator + "Android" + File.separator + "data"
File f = new File(folder)
if (!f.exists()) {
f.mkdir()
}
String filePath = File.separator + "mnt" + File.separator + "sdcard"
+ File.separator + "Android" + File.separator + "data"
+ File.separator + "file.text"
File file = new File(filePath)
OutputStream output = null
try {
output = new FileOutputStream(file)
final byte[] buffer = new byte[1024]
int read
while ((read = stream.read(buffer)) != -1) {
output.write(buffer, 0, read)
}
output.flush()
} catch (Exception e1) {
e1.printStackTrace()
} finally {
try {
output.close()
stream.close()
} catch (IOException e) {
e.printStackTrace()
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)