title: How to convert File to String and get back that String to File again
body: <p>I have a question: "How to convert File to String and get back that String to File again in Java?" </p>
  
  <p>my code :</p>
  
  <pre><code>public static void main(String[]args) throws IOException{
      String fff = fileToString("Book.xlsx");
      byte[] bytes = fff.getBytes();
  
      File someFile = new File("Book2.xlsx");
      FileOutputStream fos = new FileOutputStream(someFile);
      fos.write(bytes);
      fos.flush();
      fos.close();
  }
  
  public static String fileToString(String file) {
      String result = null;
      DataInputStream in = null;
  
      try {
          File f = new File(file);
          byte[] buffer = new byte[(int) f.length()];
          in = new DataInputStream(new FileInputStream(f));
          in.readFully(buffer);
          result = new String(buffer);
      } catch (IOException e) {
          throw new RuntimeException("IO problem in fileToString", e);
      } finally {
          try {
              in.close();
          } catch (IOException e) { /* ignore it */
          }
      }
      return result;
  }
  </code></pre>
  
  <p>How I can getback <code>Book1.xlsx</code> in string and saved in <code>book2.xlsx</code> ?? <code>Book2.xlsx</code> is null....</p>