[英]How to get file jpg properties in Android Studio
首先,我使用getFilePaths方法獲得一個ArrayList。 方法{ 從SD卡中列出所有圖像。 }
如何繼續?
在電話上,當您在圖像上看到詳細信息時,可以看到:
標題,小時,寬度,高度,方向,文件大小,路徑...
我想獲取文件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();
}
}
}
}
好的,我使用以下簡單代碼,它在屬性文本中顯示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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.