title: Read binary file as String, edit and then back to Binary file in Android Studio (java)
body: <p>I am new to java and I code a mobile app on Android Studio 3.1x.</p>
  
  <p>I need to read a binary file as String. (Eg: abc.dll) </p>
  
  <p>Need to edit some portion of that string and write back to another binary file.
  Eg: efg.dll</p>
  
  <p>I could do it well, but when I read as String, the String looks different and wrong length.</p>
  
  <p>I know I can patch that byte[] and re write the byte[] as efg.dll.
  But I need to convert as String and back to byte[] and write efg.dll for some reason.</p>
  
  <p>My pseudo code is below:</p>
  
  <pre><code>String FileBuffer ="";
  int FileLength = 0;
  
  //I store abc.dll inside raw folder
  InputStream ipsSysTemplate =  getResources().openRawResource(R.raw.abc);
  FileLength = ipsSysTemplate.available();
  byte[] buf = new byte[FileLength];
  ipsSysTemplate.read(buf);
  ipsSysTemplate.close();
  FileBuffer = new String(buf); 
  //I even tried many Charset like "UTF-8", "windows-1252" etc...
  //FileBuffer = new String(buf,"UTF-8");  
  
  //I need both length must be same, but I get different
  System.out.println(FileLength + "  " + FileBuffer.length());
  
  //Finally I write a new binary file efg.dll from below code
  File file = new File(/storage/emulated/0/Download/efg.dll);
  file.createNewFile();
  FileOutputStream fos = new FileOutputStream(file);
  fos.write(FileBuffer.getBytes());
  fos.close();
  </code></pre>
  
  <p>When I do this similar code in Eclipse on Window 7, I get expected result.
  But in that case I place my template abc.dll on HDD.</p>
  
  <p>I don't know where is the issue and what I need to know more...
  On the concept of java or Android mobile.</p>
  
  <p>Could some expert understand my problem and give me a simple solution please ?</p>
  
  <p>This is how both files look after my code.
  <a href="https://i.stack.imgur.com/P6PuM.jpg" rel="nofollow noreferrer">please have a look at this image</a></p>
  
  <p>Thanks in advance...</p>
  
  <p>gaamaa</p>