title: java save binary code to a file
body: <p>I'm retrieving a picture file as binary code through ajax, then javascript passes it to java on android and android is getting the binary code but I can't make it save it... I have tried many diiferent ways and nothing works.</p>
  
  <p>the code on java so far looks like this:</p>
  
  <pre><code> public void setFile(String sFileName, String sBody){
      try
      {
          //Log.w("setfile", sBody);
          File root = new File(Environment.getExternalStorageDirectory(), local_address);
          if (!root.exists()) {
              root.mkdirs();
          }
          File gpxfile = new File(root, sFileName);
          FileOutputStream aFileOutStream = new FileOutputStream(gpxfile);
          DataOutputStream aDataOutputStream = new DataOutputStream(aFileOutStream);
  
  
          aDataOutputStream.writeUTF(sBody);
          aDataOutputStream.flush();
          aDataOutputStream.close();
          aFileOutStream.close();
  
          //FileWriter writer = new FileWriter(gpxfile);
          //writer.append(sBody);
          //writer.flush();
          //writer.close();
          //Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
      }
      catch(IOException e)
      {
           e.printStackTrace();
      }
     }  
  </code></pre>
  
  <p>i know java is working because if I uncomment this line</p>
  
  <p>//Log.w("setfile", sBody);</p>
  
  <p>log cat would return the binary code that javascript sent java</p>