Java 如何在Android Studio中获取文件jpg属性
首先,我使用getFilePath方法获得一个ArrayList。 方法{} 如何继续 在手机上,当您在图像上看到详细信息时,您可以看到: 标题、小时、宽度、高度、方向、文件大小、路径 我想获得文件jpg的所有属性/细节/属性,并将它们保存在变量中Java 如何在Android Studio中获取文件jpg属性,java,android,file,Java,Android,File,首先,我使用getFilePath方法获得一个ArrayList。 方法{} 如何继续 在手机上,当您在图像上看到详细信息时,您可以看到: 标题、小时、宽度、高度、方向、文件大小、路径 我想获得文件jpg的所有属性/细节/属性,并将它们保存在变量中 我尝试过这样做:但我认为这不是正确的方法您可以像下面的代码一样从文件中检索属性将您的文件添加到下面的代码中并获取属性对象 Properties prop = new Properties(); // load a prop
我尝试过这样做:但我认为这不是正确的方法您可以像下面的代码一样从文件中检索属性将您的文件添加到下面的代码中并获取属性对象
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();
}
}
}
}
好的,我使用这个简单的代码,它在属性文本中显示null:
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
也许这有助于您使用Java中的Properties类来管理.Properties文件,以便组织应用程序配置,而不是获取文件属性“首先,我使用方法GetFilePath.method{列出SD卡中的所有图像。}”获取ArrayList”——该代码与SD卡无关,效率低下。“您可以看到:标题、小时、宽度、高度、方向、文件大小、路径”--这些都是元数据片段。如果您在
MediaStore
中查询图像,不仅可以获得数据,而且应该比您的“扫描整个外部存储区域的图像”方法运行得更快。ty commonware,我将尝试一下。但是,我需要知道如何从一个目录中获取所有图像(在我的例子中是whatsapp图像)变量myDir中的what/why“Chetan”?您可以直接传递您的文件,它是我的代码,您可以删除它。您可以传递您的文件对象来代替myFile。