简体   繁体   English

是否可以创建一个新文件夹?

[英]Is it possible to create a new folder?

Is it possible to create a new folder for images (to be taken through my app) to be stored in, on the android phone? 是否可以为要存储在Android手机上的图像(通过我的应用拍摄)创建一个新文件夹? (Or SD Card as far as I'm concerned). (就我而言,还是SD卡)。 I could name it what I like [Maybe the name of my app so the files are easily found] and then the images taken by launching the camera through my app will be stored there. 我可以根据自己的喜好命名[也许是我的应用程序的名称,这样就可以轻松找到文件],然后通过我的应用程序启动相机拍摄的图像将存储在此处。 I'm thinking it might have something to do with Uri's. 我认为这可能与Uri's有关。 (Just a guess.) (只是一个猜测。)

use this code 使用此代码

String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/saved_images");   
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".jpg";
File file = new File (myDir, fname);
if (file.exists ()) file.delete (); 
try {
       FileOutputStream out = new FileOutputStream(file);
       finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
       out.flush();
       out.close();

} catch (Exception e) {
       e.printStackTrace();
}

and add this in manifest 并在清单中添加

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

check this link Android saving file to external storage 检查此链接Android将文件保存到外部存储

Just use File operation for that.. 只需使用文件操作即可。

File imageDirectory = new File("/sdcard/Images/"); // Path for location where you want to make directory, Internal or External storage
// have the object build the directory structure, if needed.
imageDirectory.mkdirs();

And in Application's manifest file put permission.. 并在Application的清单文件中放入权限。

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

Why not? 为什么不?

String path = Environment.getExternalStorageDirectory().getAbsoluteFile() + "/YourAppRootDir"; 
File dir = new File(path);
dir.mkdirs();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM