简体   繁体   中英

How to get file jpg properties in Android Studio

Firstly I get an ArrayList using the method getFilePaths. method { List out all images from SD card. }

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.

I tried do this: Properties Class Java but I think that's not the right way

You can retrieve Properties from File like below code add your file into below code and get Properties object

  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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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