拷貝assets下的文件

/**spa

* 拷貝assets下的文件get

input

* @param assetFilePathstring

*            assets的文件路徑it

* @param toio

*            拷貝到的路徑ast

*/file

public static void copyAssetFile(String assetFilePath, String to)static

{di

InputStream inputStream = null;

FileOutputStream fileOutputStream = null;

try

{

inputStream = ApplicationData.globalContext.getAssets().open(

assetFilePath);

File toDir = new File(to);

toDir.mkdirs();

File toFile = new File(

toDir.getAbsolutePath()

+ "/"

+ assetFilePath.substring(assetFilePath

.lastIndexOf("/") + 1));

fileOutputStream = new FileOutputStream(toFile);

byte[] buffer = new byte[BUFFER_SIZE];

for (int bytesRead = 0; (bytesRead = inputStream.read(buffer, 0,

buffer.length)) != -1;)

{

fileOutputStream.write(buffer, 0, bytesRead);

}

} catch (Exception e)

{

e.printStackTrace();

} finally

{

try

{

if (inputStream != null)

{

inputStream.close();

}

if (fileOutputStream != null)

{

fileOutputStream.close();

}

} catch (Exception e)

{

e.printStackTrace();

}

}

}

相關文章
相關標籤/搜索