Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Read from external text file

    So I'm trying to get my jsp file to read from a text file that's not located on the server. I can get it to read from a local file just fine:

    Code:
    BufferedReader input = new BufferedReader(new FileReader("/path/to/my/local/file/articleOrder.txt"));
     
     String line = "";
     while ((line=input.readLine()) != null)
     {
    	 out.print(line);
     }
    But this is what I'm trying to do:

    Code:
    BufferedReader input = new BufferedReader(new FileReader("http://path.com/to/my/external/file/articleOrder.txt"));
     
     String line = "";
     while ((line=input.readLine()) != null)
     {
    	 out.print(line);
     }
    I tried passing a URI to the FileReader, but I don't think I'm doing it correctly, or if its even possible to pass a URI to the FileReader.

  • #2
    Regular Coder
    Join Date
    Feb 2008
    Location
    Edinburgh - Scotland
    Posts
    107
    Thanks
    0
    Thanked 12 Times in 12 Posts
    You wana pass the InputStream for the URL, so I would make a URL object for your URL and pass the URL inputstream to the BufferedReader.


  •  

    Posting Permissions

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