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.
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.
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,
can u tell me, what type of file you want to read?
Last edited by mail_rahman; 2008-10-06 at 08:10.
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.
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,
hi,
yes dude..No links in wiki for trial code??
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 11:04.
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,
if you are woring with File Connection, then its diffrent procedure.
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
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,
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,
hi,
actually my application change suddenly so at present i haven't use that code..But may be in future i may use..
rohanwaugh
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,