Java 此块是否选择图像或其路径?

Java 此块是否选择图像或其路径?,java,Java,我知道这段代码通过路径查找照片,但我不知道photo变量中有什么 fileName = f.getAbsolutePath(); try { File image2 = new File(fileName); FileInputStream fis = new FileInputStream(image2); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte

我知道这段代码通过路径查找照片,但我不知道photo变量中有什么

fileName = f.getAbsolutePath();
try {
    File image2 = new File(fileName);
    FileInputStream fis = new FileInputStream(image2);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    byte[] buf = new byte[1024];
    for(int readNum; (readNum=fis.read(buf))!=-1;) {
        bos.write(buf, 0, readNum);
    }
    photo = bos.toByteArray();
} catch(Exception e1) {
    JOptionPane.showMessageDialog(null, e1);
}

下面的代码只是获取照片的字节数组,这意味着照片的内容采用字节数组格式

fileName = f.getAbsolutePath();
try {
    //Getting file object from the filePath
    File image2 = new File(fileName);
    // create input stream for that image object
    FileInputStream fis = new FileInputStream(image2);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    byte[] buf = new byte[1024];
    // below repeated logic read the fis object till its empty and write into byte array object
    for(int readNum; (readNum=fis.read(buf))!=-1;) {
        bos.write(buf, 0, readNum);
    }
    photo = bos.toByteArray();
} catch(Exception e1) {
    JOptionPane.showMessageDialog(null, e1);
}

照片只是一个字节[]。大概是图像文件的字节。用文本编辑器打开图像,这就是存储在照片中的内容。您将看到字符,但这只是构成图像的字节的表示形式。