Reading a remote file using Java

前端 未结 7 1524
礼貌的吻别
礼貌的吻别 2020-12-06 04:28

I am looking for an easy way to get files that are situated on a remote server. For this I created a local ftp server on my Windows XP, and now I am trying to give my test a

7条回答
  •  暖寄归人
    2020-12-06 05:20

    I find this very useful: https://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html

    import java.net.*;
    import java.io.*;
    
    public class URLReader {
        public static void main(String[] args) throws Exception {
    
            URL oracle = new URL("http://www.oracle.com/");
            BufferedReader in = new BufferedReader(
                new InputStreamReader(oracle.openStream()));
    
            String inputLine;
            while ((inputLine = in.readLine()) != null)
                System.out.println(inputLine);
            in.close();
        }
    }
    

提交回复
热议问题