Reading a text file from a URL

I am having problems trying to read a text file from a URL.
This is the code i have been using:
package Java;
import java.net.*;
import java.io.*;
public class Main_1 {
public static void main(String[] args) throws Exception {
     URL myAddress = new URL("http://www.geocities.com/simonrobinson1/java/farrago.txt");
     BufferedReader in = new BufferedReader(
                    new InputStreamReader(
                    myAddress.openStream()));
     String inputLine;
     while ((inputLine = in.readLine()) != null)
     System.out.println(inputLine);
     in.close();
but it returns an error saying:
java.net.NoRouteToHostException: Operation timed out: no further information
at java.net.PlainSocketImpl.socketConnect(Native Method) .....etc etc.
Is this just a problem due to my network or is there something wrong with my code ????

Altho you can access the file by typing the URL in a browser, geocities being a free web-hosting service don't like you to access the materials without seeing their ads. You have to find a way to trick it into thinking that you are indeed coming in from a web browser even tho you aren't.
V.V.

Similar Messages

  • Read a text file from DB directly (don't use PLSQL).

    how can I Read a text file from DB directly (don’t use PLSQL). ?

    If there is a known structure, you could use External Table access and query that "file" as any table.
    Nicolas.

  • How to read a text file from a Jar file

    Hi
    How can I read a text file from a Jar file?
    Thanx in advance..

    thanx
    helloWorld it works.damn, I didn't remove it fast enough. Even if it is urgent, it is best not to mention it, telling people just makes them take longer.

  • Reading a text file from a remote host. Authentication required.

    Hi frnds,
    I have to read a text file "config.txt" from a remote host "HOSTNAME". File is shared in a folder - "FOLDER" .
    If the folder is shared with no password protection then it works. But if the folder is password protected the code is unable to read the file.
    I know the UserName and PassWord of the shared folder. How to code for this.
    I don't want to share the Folder to everyone without a password.
    Kindly Help.
    try {
    FileReader fr=new FileReader("\\\\HostName\\folder\\config.txt");
    BufferedReader br=new BufferedReader(fr);
    String s=null;
    while((s=br.readLine())!=null)
    /* One line is read */
    fr.close();
    catch(Exception e)
    throw new Exception("Exception in ConfigConstants."+e.toString());
    urs
    Mishra

    ok.. let me define it clearly...
    By using ftp as a protocol how can I read a text file
    in remote machine........ kindly do reply....Have a look at this article:
    http://www.javaworld.com/javaworld/jw-04-2003/jw-0404-ftp.html
    and what are the prerequisities that are needed for
    such a type of operation.....(At least) an FTP server should be running on the machine where the text file resides.
    Message was edited by:
    prometheuzz
    Oh, you should have your keyboard fixed: the full stop key seems to be stuck, you have a lot of trailing ..... after each sentence.

  • Sample code to read a text file from UNIX directory.

    I am using 9i Developer Suite, application server is 9.0.4. I want some help on how to read a flat file from UNIX environment. A sample code could be very helpful.
    In windows, i use this kind of code:-
    I declare an object & then write to a file using these sample staements:-
    file_handle text_io.file_type;
    filename := 'd:\ran\egs\uninvoiced.txt';
    file_handle:=text_io.fopen(filename,'w');
    text_io.put_line(file_handle, 'MOBILE NO '||'COUPON NO ' || 'DATE');
    I hope, my question is clear. Please help in solving the doubt.
    Regards.

    filename := 'd:\ran\egs\uninvoiced.txt';This is a Windows directory, so it won't work on Unix.
    For the rest of the code: see examples in the Forms Builder Online Help.

  • Reading a text-file from within a Jar-file...

    I've made a program, that reads from a text-file. And it works great. But when I try to put the program into a jarfile, I get a fileNotFoundException... I have the textfile both inside and outside the jarfile... with the same result.
    Does anyone know what I might be doing wrong?
    Thanx in advance!
    Martin

    Depends on the path you enter for the text file. If you simply put "filename.txt" then you should try to have the file in the same directory as the class which accesses the file.
    Cheers,
    H�vard

  • How to read a text file from other machine???

    I have a text file located in local machine. I use th e code below to retrieve data from that particular text file.
    String realPath     = (String)getServletContext().getRealPath("");
    BufferedReader holsFile = new BufferedReader(new FileReader(realPath + "/webpages/holidays.txt"));My question is , how could I retrieve the records from the tsxt file if the file is located in another machine or webserver?
    Thanks for advanced.

    It's ok to be new.
    The answer is yes. (But I'll let you look in the javadoc to see which package it's in).
    Also it may be worth understanding that there is no such thing as a "function" in java, operations are termed "methods". To go further, you should realise that URL is a class not a "function" or method. The parentheses mean you're calling the constructor.
    HTH
    /k1

  • How to read a text file from Visual Composer

    Hi VC Experts,
    Please suggest me how can we read a textfile from  the local machine and pull the data from Visual Composer.
    Regards
    Kiran

    Hy kiran, is not possible to read data from flat file and put it in visual composer but you can :
    1) load this file in BI by ETL, for example on DSO object and then you can create a bex query to retrive the data
    2) if you want display the content of this file , you can use KM.
    Regards,
    Andrea

  • Reading text file from database server in OA Page

    Hi Guys,
    I am trying to embed an applet with in an OA Page. The applet is used to mainly for showing Gantt chart. I have to pass my connection details from OA Page to applet, I dont pass directly the connection details to the applet so i am placing all the server details, user name and password in a text file on the database server.
    So from the OA Page i have to read the contents of the file on the database server and pass them to the applet using the <PARAM> tag. My question is how to read the text file from the database server.Any Inputs?
    Thanks in advance for your help.
    Regards,
    Nagesh Manda.

    If the file to be read is on the database, then it makes sense to use the pl/sql code to read the file. Make a call to this pl/sql code from page controller to get back the values.
    --Shiv                                                                                                                                                                                                                                                                                                                                                                                           

  • How to download a text file from the server

    hi everyone,
    can anyone tell me how to download and read a text file from the server and saved in into resource folder.
    with regards
    pallavi

    its really easy
    To read from server, use something like:
    HttpConnection connector = null;
    InputStream inp_stream = null;
    OutputStream out_stream = null;
    void CloseConnection()
         if(inp_stream!=null)inp_stream.close();
         inp_stream=null;
         if(out_stream!=null)out_stream.close();
         out_stream=null;
         connector.close();
         connector = null;
    public void getResponse(String URL,String params)
      try
         if(connector==null)connector = (HttpConnection)Connector.open(URL);//URL of your text file / php script
         connector.setRequestMethod(HttpConnection.POST);
         connector.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.1");
         connector.setRequestProperty("content-type", "application/x-www-form-urlencoded");
         //connector.setRequestProperty("charset","windows-1251");
         //*** If you need to send ("arg1=value&arg2=value") arguments to script use this:
         out_stream = connector.openOutputStream();
         byte postmsg[] = params.getBytes();
         out_stream.write(postmsg);
         int rc = connector.getResponseCode();//in any case here connection will be opened & closed
         if (rc != HttpConnection.HTTP_OK)
              CloseConnection();
              throw new IOException("HTTP response code: " + rc);
         inp_stream = connector.openInputStream();
         int pack_len = inp_stream.available();
         byte answ[]=new byte[pack_len];
         inp_stream.read(answ);
         CloseConnection();
         ProcAnswer(answ);//process received data
      catch(Exception ex)
         System.err.println("ERROR IN getResponse(): "+ex);
    } And you can read from resource file like
    public void loadFile(String filename)
        DataInputStream dis = new DataInputStream(getClass().getResourceAsStream("/"+filename));
        String str="";
        try
             while (true)
                ch = dis.read();//read character
                if(ch=='\r')continue;//if file made in windows
                if(ch=='\n' || ch==-1)//end of line or end of file
                    if(str.length()==0)continue;//if empty line
                    //do some thing with "str"
                    if(ch==-1)break;//it was last line
                    str="";//next line
                    continue;
                 str+=(char)ch;
           dis.close();
       catch (Exception e)
           System.err.println("ERROR in loadFile() " + e);
    }Welcome! =)
    Edited by: MorskoyZmey on Aug 14, 2008 3:40 AM

  • How can I read text files from LAN if I only know the hostname?

    I'm new in Java Developing, and dont know the written classes yet. I need help, how to do the following steps?
    <p>1. How can I read text files from LAN if I only know the hostname, or IP address?
    <p>2. How to read lines from text files without read all lines from the beginning of file, just seek to a position.
    (ex. how can I read the 120th line?)
    <p>Please help!
    <p>sorry for the bad english

    I'm new in Java Developing, and dont know the written classes yet. I need help, how to do the following steps?
    1. How can I read text files from LAN if I only know the hostname, or IP address?You need to know the URL of the file. You need to know the hostname, port, protocl and relative path.
    The hostname is server, not file.
    2. How to read lines from text files without read all lines from the beginning of file, just seek to a position.Use the seek() to get to a random byte.
    (ex. how can I read the 120th line?)The only way to find the 120th line is to read the first 120 lines. You can use other file formats to find the 120th line without reading the whole file but to need to be able to detremine where the 120th line is

  • Reading and writing to a text file from an Applet

    I'm a novice java programming with very little formal programming training. I've pieced together enough knowledge to do what I've wanted to do so far...
    However, I've been unable to figure out how to read and write to a text file from an Applet (I can do it from a normal java program just fine). Here is a simple example of what I'd like to do (you can also look at it on my website: www.stat.colostate.edu/~leach/test02/test02.html). I know that there is some problem with permission/security but I'm not smart enough to understand what the error messages are telling or understand the few books I have. If anyone can tell me how to get this applet to work, or direct me to some referrences that would help me out I'd really appreciate it.
    Thanks,
    Andy
    import java.applet.Applet;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    public class test02 extends Applet {
    public Button B_go;
    public GridBagConstraints c;
    public void init() {
    this.setLayout(new GridBagLayout());
    c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    B_go = new Button("GO");
    c.gridx=1; c.gridy=0; c.gridwidth=1; c.gridheight=1;
    c.weightx = c.weighty = 0.0;
    B_go.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    print_stuff();
    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    this.add(B_go,c);
    public static void print_stuff() {
    try{
    File f = new File("test02.txt");
    PrintWriter out = new PrintWriter(new FileWriter(f));
    out.print("This is test02.txt");
    out.close();
    }catch(IOException e){**/}
    }

    I have almost the exact same problem, and I am in the same situation as you are with respects to the language.
    I am simply trying to create a file and output some garbage to it but my applet always spits back a security violation. I've tried eliminating the restrictions on the applet runner I use but I still get the error.
    My method:
    debug = new Label() ;
    debug.setLocation( 20, 20 ) ;
    debug.setSize( 500, 15 ) ;
    add( debug ) ;
    // output
    try
         OutputStream file = new FileOutputStream( new File( "" + getCodeBase() + "output.txt" ) ) ;
         byte[] buffer = { 1, 2, 3, 4, 5 } ;
         file.write( buffer ) ;
         file.close() ;
    } catch( Exception e )
         debug.setText( e.toString() ) ;
         Can anyone tell why this isnt working?

  • From an Oracle form, I want to read a text file.

    From an Oracle form, I want to read a text file. In the form on a button press I have:
    declare
    in_file Text_IO.File_Type;
    linebuf VARCHAR2(1800);
    filename VARCHAR2(30);
    BEGIN
    filename:=GET_FILE_NAME('U:\ora_devl\pps\work\a.txt', File_Filter=>'Text Files (*.txt)|*.txt|');
    in_file := Text_IO.Fopen(filename, 'r');
    LOOP
    Text_IO.Get_Line(in_file, linebuf);
    -- :text_item5:=:text_item5||linebuf||chr(10);
    Text_IO.New_Line;
    END LOOP;
    EXCEPTION
    WHEN no_data_found THEN
    Text_IO.Put_Line('Closing the file...');
    Text_IO.Fclose(in_file);
    END;
    It gets an ORA-302000. I suspect the problem starts with the GET_FILE_NAME because when I comment out everything but that, It processes endlessly never ending.
    Forms [32 Bit] Version 11.1.1.3.0 (Production)
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    What can you tell me? Thanks

    GET_FILE_NAME will try to open an "Open File" dialog on the server, which obviously can't happen. If you want to use that type of behavior you need to use WebUtil and the function CLIENT_GET_FILE_NAME. Example:
         filename := CLIENT_GET_FILE_NAME('C:\', File_Filter=> 'Text Files (*.txt)|*.txt|All Files (*.*)|*.*|', dialog_type=> OPEN_FILE);Refer to the Builder Online help for more details. You can also refer to the demo which is available here:
    http://www.oracle.com/technetwork/developer-tools/forms/downloads/index.html
    More information here:
    http://www.oracle.com/technetwork/developer-tools/forms/webutil-090641.html
    Also, it appears that you are attempting to use a mapped drive ("U"). Although this can be made to work, it is not recommended and in some cases will not be supported. If you need access to remote files, you should use some other mechanism to bring the file to the local machine before manipulating it.

  • Reading text file from forms6i

    hi all ,
    i want to read a text file how can i classify its coordinates (columns) to insert it into different columns of a table .
    i want that first ten characters of text file will go in first column of table , next 5 characters will go into 2nd column and so.
    but how to identify the characters from - to for columns.
    Message was edited by:
    Najeeb ur Rehman

    declare
    v_line varchar2(2000);
    v_text_io TEXT_IO.FILE_TYPE;
    begin
    v_text_io:= TEXT_IO.FOPEN(c:\temp\file.txt,'r');
    LOOP
    TEXT_IO.GET_LINE(v_text_io, v_line);
    v_first_column:= SUBSTR(v_line,1,10);
    v_second_column:= SUBSTR(v_line,11,5);
    INSERT INTO your_table VALUES(v_first_column, v_second_column);
    END LOOP;
    EXCEPTION
    WHEN no_data_found
    THEN
    TEXT_IO.FCLOSE(v_text_io);
    END;
    You can also try it with the sql-loader.
    tom

  • How to read two text files using the Read from spreadsheet.vi and then plot it

    I need to read two text files using the read from spreadsheet function and then plot these files over time.
    The file with the .res extention is the RMS values (dt and df) and the second file contains the amplitude of a frequency spectrum.
    I really appreciate any help..thanks
    Attachments:
    RMS.txt ‏1 KB
    FREQUENCY.txt ‏1 KB

    From NI Example Finder:
    Write to Text File.vi
    Read from Text File.vi
    Jean-Marc
    LV2009 and LV2013
    Free PDF Report with iTextSharp

Maybe you are looking for

  • My contact names will not display with incoming calls

    I just received the I-phone 4S.  I had the 3GS.  I have synced properly on i-tunes, but now some of my contact names do not show up on incoming calls.  Help.

  • HT202663 wifi no hardware installed

    wifi no hardware installed

  • Why isn't my mobile number an option to use for imessage?

    my iMessage & Facetime is working but its not giving my mobile number as an option to receive & send. Its only allowing my email address to be used & it keeps saying iMessage & Facetime unsuccessful activation turn iMessage on.

  • RAW CONVERSION FOR NIKON D3200 ON XP??

    I have done the download that I was told to do on the forum for the latest version of RAW conversion and now the RAW info on the Plug Ins in help has completely gone and I still cannot open RAW files. I am becoming very frustrated!

  • Trying to turn my G5 into an Airport

    I have a G5 with an ethernet port and an Airport card, running Mac OS X on a cable connection. I have been following the procedures to convert the Mac into an Airport device so I can connect it to my iPhone. When I turn internet sharing on, it turns