You Are Here:

Community: Developer Discussion Boards

#1 Old How to read file? - 2008-10-06, 06:57

Join Date: Aug 2008
Posts: 402
rohanwaugh
Offline
Regular Contributor
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.
Reply With Quote

#2 Old Thumbs up Re: How to read file? - 2008-10-06, 08:47

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
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
Reply With Quote

#3 Old Re: How to read file? - 2008-10-06, 09:00

Join Date: Dec 2006
Posts: 23
mail_rahman
Offline
Registered User
can u tell me, what type of file you want to read?
Last edited by mail_rahman : 2008-10-06 at 09:10.
Reply With Quote

#4 Old Re: How to read file? - 2008-10-06, 09:09

Join Date: Aug 2008
Posts: 402
rohanwaugh
Offline
Regular Contributor
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.
Reply With Quote

#5 Old Thumbs up Re: How to read file? - 2008-10-06, 09:14

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
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
Reply With Quote

#6 Old Re: How to read file? - 2008-10-06, 09:22

Join Date: Aug 2008
Posts: 402
rohanwaugh
Offline
Regular Contributor
hi,

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

Rohanwaugh
Reply With Quote

#7 Old Re: How to read file? - 2008-10-06, 09:32

Join Date: Dec 2006
Posts: 23
mail_rahman
Offline
Registered User
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.
Reply With Quote

#8 Old Re: How to read file? - 2008-10-06, 11:34

Join Date: Sep 2007
Posts: 874
honest_success's Avatar
honest_success
Offline
Forum Nokia Champion
You can even use FIle Connection API.
Reply With Quote

#9 Old Thumbs up Re: How to read file? - 2008-10-06, 12:45

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
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
Reply With Quote

#10 Old Re: How to read file - 2008-10-06, 13:24

Join Date: Dec 2006
Posts: 23
mail_rahman
Offline
Registered User
if you are woring with File Connection, then its diffrent procedure.
Reply With Quote

#11 Old Re: How to read file? - 2008-10-06, 13:35

Join Date: Aug 2008
Posts: 402
rohanwaugh
Offline
Regular Contributor
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
Reply With Quote

#12 Old Thumbs up Re: How to read file? - 2008-10-06, 13:49

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
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
Reply With Quote

#13 Old Thumbs up Re: How to read file? - 2008-10-07, 06:42

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
raj_J2ME
Offline
Forum Nokia Champion
Hi,
Did you fix your problem...
Thanks


Thanks

R a j - The K e r n e l
Reply With Quote

#14 Old Re: How to read file? - 2008-10-07, 06:45

Join Date: Aug 2008
Posts: 402
rohanwaugh
Offline
Regular Contributor
hi,

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

rohanwaugh
Reply With Quote

#15 Old Thumbs up Re: How to read file? - 2008-10-07, 06:55

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
raj_J2ME
Offline
Forum Nokia Champion
Ok..
No probs . i just ask that if a thread was started then it must be finished..
Enjoyeee..


Thanks

R a j - The K e r n e l
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
Similar Threads
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

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