简体   繁体   English

如何在Android Studio中获取文件jpg属性

[英]How to get file jpg properties in Android Studio

Firstly I get an ArrayList using the method getFilePaths. 首先,我使用getFilePaths方法获得一个ArrayList。 method { List out all images from SD card. 方法{ 从SD卡中列出所有图像。 } }

How to continue? 如何继续?

At phone, when you see details over image, you can see: 在电话上,当您在图像上看到详细信息时,可以看到:

tittle, hour, width, height, orientation, fileSize, path... 标题,小时,宽度,高度,方向,文件大小,路径...

I want get all attributes/details/properties of a file jpg and save them in variables. 我想获取文件jpg的所有属性/详细信息/属性,并将其保存在变量中。

I tried do this: Properties Class Java but I think that's not the right way 我尝试这样做: Properties Class Java,但我认为这不是正确的方法

You can retrieve Properties from File like below code add your file into below code and get Properties object 您可以从文件中检索属性,如以下代码所示,将文件添加到以下代码中并获取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();
                }
            }
        }

    }

Ok, I using this simple code and it show null in property text: 好的,我使用以下简单代码,它在属性文本中显示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.

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