try {
    URL url = newURL( "http://網址" );
   
HttpURLConnection connect = (HttpURLConnection) url.openConnection();
    connect.setDoInput(
true );
    connect.setDoOutput(
true );
    connect.setRequestMethod(
"POST" );

   
if ( connect.getResponseCode() == 200 ) {
       
File outFile = newFile( "檔案路徑" );
       
OutputStream out = newFileOutputStream( outFile );

       
InputStream in = connect.getInputStream();
        copy( in, out, 32 );
        in.close();
        out.close();
    }

    connect.disconnect();
} catch ( MalformedURLException e ) {
    e.printStackTrace();
} catch ( IOException e ) {

    e.printStackTrace();
}

創作者介紹
創作者 阿偉隨想 的頭像
moneyd

阿偉隨想

moneyd 發表在 痞客邦 留言(0) 人氣( 1763 )