如何在Android Studio中获取文件jpg属性
首先,我使用方法getFilePaths获取ArrayList。 方法{List out all images from SD card.}如何在Android Studio中获取文件jpg属性
如何继续?
在手机,当你看到了图像的细节,你可以看到:
丝毫不差,小时,宽度,高度,方向,档案大小,路径...
我想要得到的所有属性/详细资料/一个文件jpg的属性并将它们保存在变量中。
我试着这样做:Properties Class Java,但我认为这是不正确的做法
您可以从文件中像下面的代码检索属性添加文件到下面的代码,并获得Properties对象
Properties prop = new Properties();
// load a properties file
prop.load(input);
private void retrievePropertiesFromFile(){
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/CHETAN");
String fname = "mytext.txt";
File myFile = new File (myDir, fname);
InputStream input = null;
try {
input = new FileInputStream(myFile);
Properties prop = new Properties();
// load a properties file
prop.load(input);
// get the property value and print it out
Log.i(getClass().getSimpleName(),prop.getProperty("text"));
Log.i(getClass().getSimpleName(),prop.getProperty("textstyle"));
Log.i(getClass().getSimpleName(),prop.getProperty("typeface"));
Log.i(getClass().getSimpleName(),prop.getProperty("typeface"));
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
什么/为什么“Chetan”变量myDir? –
您可以直接传递您的文件,其代码我可以删除它 –
您可以传递您的文件对象代替myFile。 –
好,我用这个简单的代码,并将其显示在属性text空:
File imageJPG = new File("/storage/emulated/0/WhatsApp/Media/WhatsApp Images","6gMRtQyY.jpg");
if(imageJPG.isFile()){
System.out.println("its file");
System.out.println("image: "+imageJPG);
}else{
System.out.println("no");
}
InputStream input = null;
try {
input = new FileInputStream(imageJPG);
Properties prop = new Properties();
prop.load(input);
// get the property value and print it out
System.out.println("property text: "+prop.getProperty("text"));
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Console:
I/System.out: its file
I/System.out: image: /storage/emulated/0/WhatsApp/Media/WhatsApp Images/6gMRtQyY.jpg
I/System.out: property text: null
也许这可以帮助你 http://stackoverflow.com/questions/12623302/get-met Android的 来自Java的属性类用于管理.properties文件,以组织您的应用程序配置,而不是获取文件属性 – JCoder
“首先,我使用方法getFilePaths获取ArrayList。方法{列出所有来自SD卡的图像}“ - 该代码与SD卡无关并且效率低下。”您可以看到:tittle,hour,width,height,orientation,fileSize,path“ - 那些是来自MediaStore的元数据(https://developer.android.com/reference/android/provider/MediaStore.Images.ImageColumns.html)。如果您查询“MediaStore”的图像,而不是只有你会得到这些数据,但它应该比你的“扫描整个外部存储区的图像”方法运行得更快。 – CommonsWare
ty commonsware,我会去尝试一下。但是,我需要知道如何从目录中获取所有图像, (whatsapp图像在我的情况下) –