title: java : upload files to HTTP server using POST, server code issue?
body: <p>I am new to java and I have to transfer file from Android application to server. I took help from the link </p>
  
  <p><a href="http://reecon.wordpress.com/2010/04/25/uploading-files-to-http-server-using-post-android-sdk/" rel="nofollow">Uploading files to HTTP server using POST. Android SDK</a></p>
  
  <pre><code>&lt;?php
  $target_path  = "./";
  $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
  if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
   echo "The file ".  basename( $_FILES['uploadedfile']['name']).
   " has been uploaded";
  } else{
   echo "There was an error uploading the file, please try again!";
  }
  ?&gt;
  </code></pre>
  
  <p>Its PHP code and works perfectly fine but I have to implement the server side code in Java not in PHP.</p>
  
  <p>I googled and find the code from link <a href="http://www.jguru.com/faq/view.jsp?EID=62798" rel="nofollow">enter link description here</a></p>
  
  <pre><code>InputStream in = request.getInputStream();
          BufferedReader r = new BufferedReader(new InputStreamReader(in));
          StringBuffer buf = new StringBuffer();
          String line;
          while ((line = r.readLine())!=null) {
          buf.append(line);
          }
          String s = buf.toString();
  </code></pre>
  
  <p>I am new to java so donot know how to write this code. I have NetBeans <strong>netbeans-7.1.1-ml-javaee</strong> installed.</p>
  
  <p>Can somebody tell me that if this code is correct and how to put it in file or which type of file. I have created project but do not know how to put this code in file.</p>
  
  <p><strong>Edits:</strong></p>
  
  <p>Andriod code is working fine ... I want to develop Server code to get and save file</p>