Http post files to the server,
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.exe cute (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, 1024)> 0 ){
SwapStream. write (buff, 0, rc );
}
Byte [] in2b = swapStream. toByteArray ();
Return in2b;
}