首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

在sd卡顶用程序创建目录

2012-09-22 
在sd卡中用程序创建目录如果要想在sd卡中的一个子目录下创造文件FileOutputStream fos new FileOutputSt

在sd卡中用程序创建目录

如果要想在sd卡中的一个子目录下创造文件FileOutputStream fos = new FileOutputStream("/sdcard/Wallpaper/"+fileName); 这是错误的,需要

// create a File object for the parent directory File wallpaperDirectory = new File("/sdcard/Wallpaper/"); // have the object build the directory structure, if needed. wallpaperDirectory.mkdirs(); // create a File object for the output file File outputFile = new File(wallpaperDirectory, filename); // now attach the OutputStream to the file object, instead of a String representation FileOutputStream fos = new FileOutputStream(outputFile); 

?

当然别忘了检查sd卡存在不Environment.getExternalStorageDirectory()

热点排行