×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    413

    How to read file?

    Hi all,

    My application has 1 list.I want to read contents of a file and display the contents onto the list..

    how to do this??


    rohanwaugh.

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: How to read file?

    Hi,
    You can do so and here is the idea.
    Read the content from file as a string array.
    create a list and at the initialization time append the content in the list..

    // Code Idea //
    examplesList = new List("Select Example", List.IMPLICIT);
    for (int i = 0; i < examples.length; i++)
    examplesList.append(examples[i], null);

    examplesList.setCommandListener(this);

    Hope that this is what exactly you are looing for...
    Thanks
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    30

    Re: How to read file?

    can u tell me, what type of file you want to read?
    Last edited by mail_rahman; 2008-10-06 at 08:10.

  4. #4
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    413

    Re: How to read file?

    hi
    thanks for the reply.But how exactly to read from the file..in terms of code??I have stored my file in src folder only where my MIDlet is..I am using NetBeans ID for development..


    rohanwaugh.

  5. #5
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: How to read file?

    Hey,
    Yeah you can read your file by putting it in SRC folder..No doubt.
    What problem you are facing then..are you looking for that how to read that file ..

    Thanks
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  6. #6
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    413

    Re: How to read file?

    hi,

    yes dude..No links in wiki for trial code??

    Rohanwaugh

  7. #7
    Registered User
    Join Date
    Dec 2006
    Posts
    30

    Re: How to read file?

    put your .txt file into res folder and call this code

    StringBuffer sb = new StringBuffer();
    try {
    InputStream is = getClass().getResourceAsStream("/Properties.txt");
    int ch = 0;

    while ((ch = is.read()) != -1) {
    sb.append((char) ch);
    }
    } catch (Exception e) {
    e.printStackTrace();
    }


    Regards,
    A.Rahman
    Last edited by mail_rahman; 2008-10-06 at 11:04.

  8. #8
    Nokia Developer Champion
    Join Date
    Sep 2007
    Posts
    915

    Re: How to read file?

    You can even use FIle Connection API.

  9. #9
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: How to read file?

    Hey,
    I hope i missed you..i was not available.
    Anyways hope that you have done with it..still not then see this code

    public String readStationsFromTxt ()
    {
    int ch;
    try
    {
    InputStream inStream = getClass ().getResourceAsStream ("/mumbai_codes.txt");

    while ((ch = inStream.read ()) != -1)
    {
    stationBufferTxt.append ((char) ch);
    }
    return stationBufferTxt.toString ();
    }
    catch (Exception e)
    {
    System.out.println ("Exception caucght file reading..." + e.toString ());
    }
    return null;
    }

    Hope that it help you..Now pass this array to the creating of the list..

    Query will be answered...
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  10. #10
    Registered User
    Join Date
    Dec 2006
    Posts
    30

    Re: How to read file

    if you are woring with File Connection, then its diffrent procedure.

  11. #11
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    413

    Re: How to read file?

    hi all,

    i have 1 text file in the same location where my midlet is.i just want to get the contents of that file and display it on to the List.

    i don't think it requires File Connection API's.What all replys are given,i am confused in this.

    Rohanwaugh

  12. #12
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: How to read file?

    Hi,
    There is no point of be confuse.Just put your file in res folder.Then read the file as per the code that i have given you.That will return you a string/string array.Pass that array to the list creation.As i given you the code -

    examplesList = new List("Select Example", List.IMPLICIT);
    for (int i = 0; i < examples.length; i++)
    examplesList.append(examples[i], null);

    all thats you need to do...
    Where are you getting confusions.

    Thnxs
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  13. #13
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: How to read file?

    Hi,
    Did you fix your problem...
    Thanks
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  14. #14
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    413

    Re: How to read file?

    hi,

    actually my application change suddenly so at present i haven't use that code..But may be in future i may use..

    rohanwaugh

  15. #15
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: How to read file?

    Ok..
    No probs . i just ask that if a thread was started then it must be finished..
    Enjoyeee..
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. Sent a file, and read it
    By fuatsungur in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2008-02-06, 18:00
  2. Unable to read file error
    By gpalvia in forum Digital Rights Management & Content Downloading
    Replies: 0
    Last Post: 2007-11-21, 07:46
  3. Does not read from file
    By osho123 in forum Symbian
    Replies: 0
    Last Post: 2006-12-01, 12:52
  4. read text file
    By ivan6502 in forum Mobile Java General
    Replies: 1
    Last Post: 2005-01-17, 21:10
  5. write and read a TInt data from the file
    By billqu in forum Symbian
    Replies: 2
    Last Post: 2004-12-27, 15:10

Posting Permissions

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