Results 1 to 6 of 6
  1. #1
    amilien is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default Loading files via HTTP

    Hello guys,

    I need to load files via HTTP protocol in my app. Could you tell me which classes of which java package should I use? I need to load files from local PC (no URL). I read javadoc for java.io.* but I didn't notice any word concerning 'http' there...

    Thanks.

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    apache commons-httpclient ?

  3. #3
    amilien is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default

    Well, probably you are right, but I'm sure it could be done by means of pure java... what I asks should be quite simple, some standard j2se class should provide this...

  4. #4
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    How about something like this?

    Java Code:
    try
    {
       java.net.URL url = new java.net.URL("http://www.mywebsite.com/someplace/test.txt");
    
       InputStreamReader inStream = new InputStreamReader(url.openStream());
       BufferedReader in = new BufferedReader(inStream);
    
       String line = in.readLine();
       while(line!=null)
       {
          System.out.println(line);
          line = in.readLine();
       }
       inStream.close();
    }
    catch(Exception e)
    {
       e.printStackTrace();
    }
    My Hobby Project: LegacyClone

  5. #5
    amilien is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default

    Thanks mrmatt1111!

    Two questions:
    1. Will it work if I mention in URL path on my local PC like "C:\example\file.txt"?
    2. Will it be still HTTP used during file loading?

  6. #6
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    Java Code:
    java.net.URL url = new java.net.URL("file:///c:/example/file.txt");
    Last edited by mrmatt1111; 11-03-2009 at 08:37 PM.
    My Hobby Project: LegacyClone

Similar Threads

  1. loading files contained within app jar file
    By thorne_ in forum New To Java
    Replies: 3
    Last Post: 05-18-2009, 02:26 PM
  2. Uploading files to server via HTTP
    By dan0 in forum New To Java
    Replies: 2
    Last Post: 03-13-2009, 06:27 PM
  3. Transfering files over HTTP
    By DannyZB in forum Networking
    Replies: 16
    Last Post: 11-09-2008, 09:50 PM
  4. loading flash files in linux
    By rajeshang in forum AWT / Swing
    Replies: 0
    Last Post: 05-31-2008, 01:59 PM
  5. External JavaScript files not loading
    By sajut in forum New To Java
    Replies: 0
    Last Post: 02-15-2008, 05:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •