Java 中調用wget 的 例子

SimoneNewco 8年前發布 | 848 次閱讀 Java wget
public class DLTest {
  public static void main( String[] args ) {
      try {
          BufferedReader adUrlReader = new BufferedReader( new FileReader( "./AdUrls.csv" ) );
          ArrayList<String> adUrlList = new ArrayList<String>();
          String line;

          while ( (line = adUrlReader.readLine()) != null ) {
              adUrlList.add( line.trim() );
          }
          adUrlReader.close();

          int fileCounter = 0;
          for ( String adUrl : adUrlList ) {
              try {
                  String cmdString = "/usr/bin/wget -v --output-document=/home/diggler/Desktop/groovy_testing/data_scrapes/Admonitor/DL/file" + Integer.to\
String(fileCounter) + " --tries=3 " + adUrl;
                  System.out.println( cmdString );
                  Runtime rt = Runtime.getRuntime();
                  Process  p = rt.exec( cmdString );
                  p.waitFor();
                  BufferedReader r = new BufferedReader(new InputStreamReader(p.getErrorStream()));
                  String s;
                  while ((s = r.readLine())!=null) {
                      System.out.println( s );
                  }
                  r.close();
              } catch ( IOException ioe ) { ioe.printStackTrace(); }
              catch ( InterruptedException ie ) { ie.printStackTrace(); }
              fileCounter++;
          }

      } catch ( IOException e ) { e.printStackTrace(); }
  }
}
 本文由用戶 SimoneNewco 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!