android 开发 怎么才能把一个文件夹安装到SD卡上,如有一个图片的文件夹
1个回答
展开全部
public FileUtils(){
//得到当前外部存储设备的目录( /SDCARD )
SDPATH = Environment.getExternalStorageDirectory() + "/";
}
/**
* 在SD卡上创建文件
* @param fileName
* @return
* @throws IOException
*/
public File createSDFile(String fileName) throws IOException{
File file = new File(SDPATH + fileName);
file.createNewFile();
return file;
}
/**
* 在SD卡上创建目录
* @param dirName
* @return
*/
public File createSDDir(String dirName){
File dir = new File(SDPATH + dirName);
dir.mkdir();
return dir;
}
/**
* 判断SD卡上的文件夹是否存在
* @param fileName
* @return
*/
public boolean isFileExist(String fileName){
File file = new File(SDPATH + fileName);
return file.exists();
}
/**
* 将一个InputStream里面的数据写入到SD卡中
* @param path
* @param fileName
* @param input
* @return
*/
public File write2SDFromInput(String path,String fileName,InputStream input){
File file = null;
OutputStream output = null;
try {
createSDDir(path);
file = createSDFile(path + fileName);
output = new FileOutputStream(file);
byte[] buffer = new byte[FILESIZE];
while((input.read(buffer)) != -1){
output.write(buffer);
}
output.flush();
}
catch (Exception e) {
e.printStackTrace();
}
finally{
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return file;
}
记得要写权限
//得到当前外部存储设备的目录( /SDCARD )
SDPATH = Environment.getExternalStorageDirectory() + "/";
}
/**
* 在SD卡上创建文件
* @param fileName
* @return
* @throws IOException
*/
public File createSDFile(String fileName) throws IOException{
File file = new File(SDPATH + fileName);
file.createNewFile();
return file;
}
/**
* 在SD卡上创建目录
* @param dirName
* @return
*/
public File createSDDir(String dirName){
File dir = new File(SDPATH + dirName);
dir.mkdir();
return dir;
}
/**
* 判断SD卡上的文件夹是否存在
* @param fileName
* @return
*/
public boolean isFileExist(String fileName){
File file = new File(SDPATH + fileName);
return file.exists();
}
/**
* 将一个InputStream里面的数据写入到SD卡中
* @param path
* @param fileName
* @param input
* @return
*/
public File write2SDFromInput(String path,String fileName,InputStream input){
File file = null;
OutputStream output = null;
try {
createSDDir(path);
file = createSDFile(path + fileName);
output = new FileOutputStream(file);
byte[] buffer = new byte[FILESIZE];
while((input.read(buffer)) != -1){
output.write(buffer);
}
output.flush();
}
catch (Exception e) {
e.printStackTrace();
}
finally{
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return file;
}
记得要写权限
更多追问追答
追问
怎样的安装的时候,把 asset下的文件夹安装到SD卡
追答
你的意思是seset有个文件要转移到sd卡?用文件系统也可以读写的啊
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询