FileName: File
http: Server address
public Boolean post (String fileName, String http) throws FileNotFoundException {
File File = new file (fileName);
InputStream in = new FileInputStream (file);
Bytearrayentity arrayentity;
try {
arrayentity = new Bytearrayentity (Input2byte (in));
Arrayentity.setcontenttype ("Application/octet-stream");
HttpPost HttpPost = new HttpPost (HTTP);
Httppost.setentity (arrayentity);
Defaulthttpclient client = new Defaulthttpclient ();
try {
int Result=client.execute (httppost). Getstatusline (). Getstatuscode ();
} catch (Exception e) {
throw new RuntimeException (e);
}
} catch (IOException E1) {
}
return false;
}
public static final byte[] Input2byte (InputStream instream)
Throws IOException {
Bytearrayoutputstream Swapstream = new Bytearrayoutputstream ();
byte[] buff = new byte[1024];
int rc = 0;
while (rc = instream.read (buff, 0, 1024x768)) > 0) {
Swapstream.write (buff, 0, RC);
}
byte[] in2b = Swapstream.tobytearray ();
return in2b;
}
HTTP POST file to server