title: Java Temporary Files, read and write
body: <p>I have this piece of code</p>
  
  <pre><code>package Classes;
  
  import java.io.*;
  
  public class IpAdministrator {
  
      public Boolean isActive(String ipAddress) {
          boolean isActive = false;
          String cmd;
          String OS = System.getProperty("os.name");
          System.out.println(OS);
          String tmpfolder = System.getProperty("java.io.tmpdir");
          System.out.println(tmpfolder);
  
          //iptmp.deleteOnExit();
  
          if (OS.equals("Linux")) {
              cmd = "ping " + ipAddress + " -c 1";
          } else {
              cmd = "cmd /c ping " + ipAddress + " -n 1";
          }
          try {
              String s = null;
              Process p = Runtime.getRuntime().exec(cmd);
              File iptmp = File.createTempFile("ipresult", ".txt", new File(tmpfolder));
  
  
              BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
  
  
              while ((s = stdInput.readLine()) != null) {
                  System.out.println(s);
                  s = s.toString();
                  BufferedWriter writer = new BufferedWriter(new FileWriter(iptmp));
                  writer.write(s);
  
              }
  
  
          } catch (Exception ex) {
              System.out.println(ex.getMessage().toString());
          }
  
  
          return isActive;
      }
  
  }
  </code></pre>
  
  <p>I want to write the result from the command in the temporary file, I found something related in other questions in this site, and it seems to work fine, but when I run this, the file is created with some random numers (ie: ipresult540677216848957037.txt) and it's empty, I can't figure out why, I also read that it's something related to java 1.7, so that means that I can't fill the file with information, there something that I'm missing?</p>