I am new to java and I have to transfer file from Android application to server. I took help from the link
Uploading files to HTTP server using POST. Android SDK
<?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!";
}
?>
Its PHP code and works perfectly fine but I have to implement the server side code in Java not in PHP.
I googled and find the code from link enter link description here
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();
I am new to java so donot know how to write this code. I have NetBeans netbeans-7.1.1-ml-javaee installed.
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.
Edits:
Andriod code is working fine ... I want to develop Server code to get and save file