You Are Here:

Community: Developer Discussion Boards

#1 Old Problem reading txt-files from the net - 2003-03-24, 15:59

Join Date: Mar 2003
Posts: 26
Elwoodini
Offline
Registered User
Hi!

I have written an application that reads a txt-file from the internet and parses it for newline("\n"). If a new line begins, the Stringbuffer is added to a vector. The result is a vector, containing the lines from the txt-file as elements. So far so good, it works phantastic with the S60-Concept emulator or the default Colour-phone emulator, but NOT on a _real_ Nokia 3650/7650.
Seems that the vector is empty, cause ive written an alert that occours on the phone, if the vector is empty. This alert occours every time after making the connection. So i think the problem must be near the line where parsing the '\n'.
If i look into the connection-log in the Nokia 3650, there is traffic (exactly the size of my txt-file). I really don´t know, where the failure is, thanks for any help!!

Here comes the code:
Code:
 private void readQuestions() {
    StreamConnection conn=null;
    InputStream in = null;
    StringBuffer data = new StringBuffer();

    try {
      // Open the HTTP connection
      conn = (StreamConnection)Connector.open("http://www.my-server.de/Fragen.txt",Connector.READ);

      // Obtain an input stream for the connection
      in = conn.openInputStream();

      // Read a line at a time from the input stream
      int ch;
      while ((ch=in.read()) != -1) {
        if ((char)ch != '\n') {
          // Read the line one character at a time
          data.append((char)ch);
        }
        else {
          // Add the question to the fragen vector
          fragen.addElement(data.toString());

          // Clear the string for the next line
          data = new StringBuffer();
        }
      }
    }
    catch (IOException e) {
      System.err.println("The connection could not be established.");
    }
    try{
    conn.close();
    }
    catch (IOException e) {
      System.err.println("Failure while closing the connection");
    }
  }
Reply With Quote

#2 Old 2003-03-24, 19:06

Join Date: Mar 2003
Posts: 26
Elwoodini
Offline
Registered User
Now i have tried the application with another net-access-protocol, (D2-Vodafone Wap via GPRS), and i had no problems!! I have noticed that the difference is in the gateway-adress (with 0.0.0.0, Adress was web.vodafone.de nothing happens, with gateway 139.7.29.1 and adress live.vodafone.com it works fine). Seems to be a provider-problem.
Reply With Quote

#3 Old Possible bug you may have encountered? - 2003-04-07, 04:04

Join Date: Mar 2003
Posts: 17
chrisnsx
Offline
Registered User
Hi,

Im a final year compsci student, and I am using very similar code to read a file from a tomcat server.

I've run into a problem, please let me know if you've run into a similar problem, or have a solution.

For sum reason when I extract a string from the file, containing say "2" or "3", and pass the string as a parameter to Integer.parseInt(), a NumberFormatException is generated, even though I KNOW the string only contains a single numerical digit..

Any ideas?
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia