×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jan 2011
    Location
    The Heart of India
    Posts
    41

    Thumbs up readLine() is not working...

    hi, i am developing a MidLet to count lines in a text file using readLine() but it's not working.. below is my code:


    private int countLine(String str){
    int num=0;
    String strng=null;
    strng=str;
    do {
    int indexOf = strng.indexOf("\n");
    if(indexOf == -1) break;
    else {
    strng = strng.substring(indexOf + 1);
    } num++;
    }
    while(true);
    return num;
    }
    private String file() throws IOException{
    int numLine;
    try {
    FileConnection fconn=(FileConnection)Connector.open("file:///E:/a.txt",Connector.READ);
    InputStream is=fconn.openInputStream();
    String iS = is.toString();
    numLine=countLine(iS);
    return Integer.toString(numLine);
    }
    catch (Exception e){
    alert = new Alert("Error", e.toString(), null, AlertType.ERROR);
    alert.setTimeout(Alert.FOREVER);
    display.setCurrent(alert, form);
    }
    return null;
    }

  2. #2
    Registered User
    Join Date
    Oct 2010
    Posts
    6

    Re: readLine() is not working...

    Method toString() (in your case InputStream.toString) is not the method to read data in stream.

    Here you will find solution how to read data from input stream.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Location
    The Heart of India
    Posts
    41

    Re: readLine() is not working...

    thank you...

Similar Threads

  1. Writing to COM port not working but reading is working
    By doitifucan in forum Mobile Java General
    Replies: 1
    Last Post: 2009-11-19, 12:10
  2. Replies: 2
    Last Post: 2009-07-24, 06:04
  3. SharedObject is not working
    By mikih in forum [Archived] Flash Lite on Nokia Devices
    Replies: 8
    Last Post: 2008-09-05, 14:37
  4. Replies: 2
    Last Post: 2006-03-11, 09:29

Posting Permissions

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