| Reply | « Previous Thread | Next Thread » |
|
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. |
| rohanwaugh |
| View Public Profile |
| Find all posts by rohanwaugh |
|
Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
raj_J2ME
Offline
Forum Nokia Champion
|
|
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 R a j - The K e r n e l |
|
can u tell me, what type of file you want to read?
Last edited by mail_rahman : 2008-10-06 at 09:10.
|
| mail_rahman |
| View Public Profile |
| Find all posts by mail_rahman |
|
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. |
| rohanwaugh |
| View Public Profile |
| Find all posts by rohanwaugh |
|
Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
raj_J2ME
Offline
Forum Nokia Champion
|
|
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 R a j - The K e r n e l |
|
hi,
yes dude..No links in wiki for trial code?? Rohanwaugh |
| rohanwaugh |
| View Public Profile |
| Find all posts by rohanwaugh |
|
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 12:04.
|
| mail_rahman |
| View Public Profile |
| Find all posts by mail_rahman |
|
You can even use FIle Connection API.
|
| honest_success |
| View Public Profile |
| Find all posts by honest_success |
|
Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
raj_J2ME
Offline
Forum Nokia Champion
|
|
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 R a j - The K e r n e l |
|
if you are woring with File Connection, then its diffrent procedure.
|
| mail_rahman |
| View Public Profile |
| Find all posts by mail_rahman |
|
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 |
| rohanwaugh |
| View Public Profile |
| Find all posts by rohanwaugh |
|
Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
raj_J2ME
Offline
Forum Nokia Champion
|
|
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 R a j - The K e r n e l |
|
Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
raj_J2ME
Offline
Forum Nokia Champion
|
|
Hi,
Did you fix your problem... Thanks Thanks R a j - The K e r n e l |
|
hi,
actually my application change suddenly so at present i haven't use that code..But may be in future i may use.. rohanwaugh |
| rohanwaugh |
| View Public Profile |
| Find all posts by rohanwaugh |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Sent a file, and read it | fuatsungur | Mobile Java Networking & Messaging & Security | 2 | 2008-02-06 19:00 |
| Unable to read file error | gpalvia | Digital Rights Management & Content Downloading | 0 | 2007-11-21 08:46 |
| Does not read from file | osho123 | General Symbian C++ | 0 | 2006-12-01 13:52 |
| read text file | ivan6502 | Mobile Java General | 1 | 2005-01-17 22:10 |
| write and read a TInt data from the file | billqu | General Symbian C++ | 2 | 2004-12-27 16:10 |