Android convert image from path to java.io.File

时间:2016-07-11 20:31:43

标签: android

I'm trying to upload file via Ion from android and i want to convert image from path such as SDCard, my code can create stream from that, but i cant create java.io.File from that, because i get this error:

Wrong 2nd argument type. Found: 'java.io.OutputStream', required: 'java.io.File' 

My code:

File imageFile = new File(photoPath);
OutputStream os = null;
try {
    os = new FileOutputStream(imageFile);
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
    os.flush();
    os.close();
} catch (Exception e) {

}

1 个答案:

答案 0 :(得分:0)

At this line:

os = new FileOutputStream(imageFile);

You should not pass the file into FileOutputStream, instead, open it with file path:

os = new FileOutputStream(path_to_file);

Here is the Java documentation.