Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5983017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:10:11+00:00 2026-05-22T22:10:11+00:00

I am trying to read some words from an online text file. I tried

  • 0

I am trying to read some words from an online text file.

I tried doing something like this

File file = new File("http://www.puzzlers.org/pub/wordlists/pocket.txt");
Scanner scan = new Scanner(file);

but it didn’t work, I am getting

http://www.puzzlers.org/pub/wordlists/pocket.txt 

as the output and I just want to get all the words.

I know they taught me this back in the day but I don’t remember exactly how to do it now, any help is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:10:12+00:00Added an answer on May 22, 2026 at 10:10 pm

    Use an URL instead of File for any access that is not on your local computer.

    URL url = new URL("http://www.puzzlers.org/pub/wordlists/pocket.txt");
    Scanner s = new Scanner(url.openStream());
    

    Actually, URL is even more generally useful, also for local access (use a file: URL), jar files, and about everything that one can retrieve somehow.

    The way above interprets the file in your platforms default encoding. If you want to use the encoding indicated by the server instead, you have to use a URLConnection and parse it’s content type, like indicated in the answers to this question.


    About your Error, make sure your file compiles without any errors – you need to handle the exceptions. Click the red messages given by your IDE, it should show you a recommendation how to fix it. Do not start a program which does not compile (even if the IDE allows this).

    Here with some sample exception-handling:

    try {
       URL url = new URL("http://www.puzzlers.org/pub/wordlists/pocket.txt");
       Scanner s = new Scanner(url.openStream());
       // read from your scanner
    }
    catch(IOException ex) {
       // there was some connection problem, or the file did not exist on the server,
       // or your URL was not in the right format.
       // think about what to do now, and put it here.
       ex.printStackTrace(); // for now, simply output it.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read some info from a text file by using windows
I'm trying to load some XY-coordinates from a asc-file. It looks like this: -55.988544
I'm trying to read in some sample data from an XML file in a
I'm experiencing some problems while trying to read a binary file in C. This
I'm trying to download some content from a dictionary site like http://dictionary.reference.com/browse/apple?s=t The problem
I'm trying to read a list of words from a txt file into a
I am trying to read some XML code from a website, and am having
I am trying to read some settings from php.ini using zend. The API that
I am trying to read some data from a python module from a web.
I'm trying to create a plugin which needs to read some data from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.