title: Java StringBuffer with Escape Char
body: <p>I have the following code shown below.   StringBuffer sbA and sbB are reading the same information.  sbA is reading it from a file (single line) , while for sbB it is hard coded in the program.   When I print them, it seems to keep the escape char is one case while not for the other.</p>
  
  <p>In my case, I would like to read the information from a file but ignore the escape char as in sbB output.  I am not sure why the outputs are different.  Any suggestions.</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.IOException;
  
  public class StringReplace {
  
       public static void main(String[] args) throws FileNotFoundException, IOException {
  
          StringBuffer sbA = new StringBuffer();
          try (BufferedReader br = new BufferedReader(new FileReader("data.txt"))) {
              for (String line; (line = br.readLine()) != null;) {
  
                  if (line.isEmpty() || line.trim().equals("") || line.trim().equals("\n"))
                  continue;
                  sbA.append(line);
              }
              br.close();
          }
  
          System.out.println("sbA:  " + sbA);
  
          StringBuffer sbB = new StringBuffer();
  
          sbB.append("{\"msgData\": \"{ \"myName\": \"TheJumper\", \"myNumber\": \"35\", \"myString\": [ \"abc\", \"efg\", \"xyz\" ] }\"}");
  
          System.out.println("sbB:  " + sbB);
  
      }
  
  }
  </code></pre>
  
  <p>The outputs are shown below:</p>
  
  <pre><code>sbA:  {\"msgData\": \"{ \"myName\": \"TheJumper\", \"myNumber\": \"35\", \"myString\": [ \"abc\", \"efg\", \"xyz\" ] }\"}
  sbB:  {"msgData": "{ "myName": "TheJumper", "myNumber": "35", "myString": [ "abc", "efg", "xyz" ] }"}
  </code></pre>
  
  <p>Screenshot of data.txt</p>
  
  <p><a href="https://i.stack.imgur.com/nvPaE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nvPaE.png" alt="enter image description here"></a></p>