0

I'm using phonegap. I have created a plugin, but now I need to save the image on the sdcard given the image url. How can I save an image? I tried using FileOutputStream to save it, and it saves it on the sdcard but my application wasn't showing the image when linking it through html tag, so I did a pull request on the file, and open it on my computer and I think the image is corrupted or something because it doesn't open correctly. Amy I using the wrong stream? Which one should I use? thanks.

EDIT: I forgot to mention that at the top level its a zip file so before I save it I do something like

FileInputInputStream inputStream = null;
ZipInputStream zipInputStream = null;

inputStream = new FileInputStream(zipFilePath);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
zipInputStream = new ZipInputStream(bufferedInputStream);
ZipEntry entry = zipInputStream.getNextEntry();
while(entry != null){
  String data = readFile(filePath); //uses zis.read(byteArra,offset,length) to read. Returns the result in a String
 saveFile(newFilePath,data); //uses FileOutputStream to save via .write( byte[] ) method

}
dchhetri
  • 6,926
  • 4
  • 43
  • 56

1 Answers1

0

The problem wasn't the stream I was using but converting the byte[] to String. Something went wrong in the conversion and so when I went to save the whole string into the file something probably got corrupted. So Instead of reading the whole file into a byte array and then converting to a string for every file type, I just do that for the text files, and for image files I just read and save through the byte array

dchhetri
  • 6,926
  • 4
  • 43
  • 56