I am trying to save a parse.com image. I need to convert it to an array of bytes. The way I decided to try to do this is apache commons-io . It does not work properly. This is my piece of code;
private void saveImage() throws IOException { // TODO Auto-generated method stub InputStream header = new FileInputStream("/ClashMMA/res/drawable-hdpi/beatdown.jpg"); ParseFile file = new ParseFile(toByteArray(header)); try{ file.save(); } catch (ParseException e) { e.printStackTrace(); } ParseObject displayImage = new ParseObject("displayImage"); displayImage.put("header", file); try{ displayImage.save(); } catch (ParseException e1){ e1.printStackTrace(); } } private byte[] toByteArray(InputStream header) throws IOException { // TODO Auto-generated method stub ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int l; byte[] data = new byte[1024]; while ((l = header.read(data, 0, data.length)) != -1) { buffer.write(data, 0, l); } buffer.flush(); return buffer.toByteArray(); }
And my mistake is this:
java.io.FileNotFoundException: /ClashMMA/res/drawable-hdpi/beatdown.jpg: open failed: ENOENT (No such file or directory)
But I'm sure there is a file, because I went to my file directory (in eclipse), right-clicked and clicked Copy Qualified Name . Which essentially copies the file path. I tried several other ways, As immediately after my computer, and in my src folder. Can someone please tell me what I am doing wrong? Why won't he read the file when it really is? Detailed explanations.
source share