Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 10-10-2008, 12:02 PM   #1 (permalink)
Rubik's Uncle!!
 
Charan's Avatar
 
Join Date: Sep 2004
Location: ಬೆಂಗಳೂರು (Bengaluru)
Posts: 3,786
Default File IO in J2ME


Hey guys,
How can one store and retrive values from a textfile using J2ME.
textfile will have content something like this

Code:
#--Configuration File--
Value1=Hello
Value2=World
I need to read the values in the following format.
Code:
string V1;
string V2;

V1=GetConfiguration(Value1);
V2=GetConfiguration(Value2);
For writing into the file I need the following format
Code:
SetConfiguration(Value1,"test1");
SetConfiguration(Value2,"test2");
is there a better way of doing it, does J2ME provide application configuration class or something like that?

This is for one of my friend.

EDIT: Or can I use XML to store data? Does J2ME support native XML reading and writing.

@Chandru.in im counting on you
__________________
i5 2400 | DH67BL | G.Skill Ripjaw 4 GB | FSP SAGA II 500W | CM 430 Black Elite | MSI R6850 Cyclone PE/OC | XBox 360 Controller | 21.5" Samsung Sync Master 2233 | 4 Mbps @75GB FUP :)
Battlefield 3 Multiplayer Discussion | Battlefield 3 Low Latency Servers List

Last edited by Charan; 10-10-2008 at 03:36 PM. Reason: Automerged Doublepost
Charan is online now  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 10-10-2008, 05:04 PM   #2 (permalink)
CAFEBABE
 
chandru.in's Avatar
 
Join Date: Mar 2008
Location: Bangalore
Posts: 474
Default Re: File IO in J2ME

Ooops!

I'm more of enterprise (Spring and Hibernate) and desktop Java developer than Mobile.

File IO is not the right way for storing preferences in Java ME as the FileConnection class may not be implemented by all devices. For storing preferences in Java ME, the RecordStore class is to be used. Ask him to look into its methods for further information, as I cannot get the exact scenario of his requirement.

He has to be careful about opening and close Recordstores as it has to be closed as many times as it is opened. Ask him to use Singleton pattern for managing configurations to avoid such hassles.
__________________
Chandru

http://tuxychandru.blogspot.com

Last edited by chandru.in; 10-10-2008 at 05:11 PM.
chandru.in is offline  
Old 10-10-2008, 05:54 PM   #3 (permalink)
In The Zone
 
Join Date: Dec 2007
Location: Mumbai
Posts: 270
Default Re: File IO in J2ME

Try this

But it requires JSR-75. If its not available and you do not have to store huge data.. solution suggested by chandru.in is a better option...
__________________
Intel Q6600, Abit IP35-E, Transcend 2GB 800Mhz, Seagate 500GB(32MB) SATA II
EVGA 9600GT 512MB DDR3 Knock Out, Dell SE198WFP
ASUS DVD R/W 20X LightScribe, Zebronics Antibiotic, Cooler Master 500W
mastermunj is offline  
Old 10-10-2008, 06:14 PM   #4 (permalink)
Rubik's Uncle!!
 
Charan's Avatar
 
Join Date: Sep 2004
Location: ಬೆಂಗಳೂರು (Bengaluru)
Posts: 3,786
Default Re: File IO in J2ME

Quote:
Originally Posted by chandru.in View Post
File IO is not the right way for storing preferences in Java ME as the FileConnection class may not be implemented by all devices.
ok then File IO is off the drawing board .

Quote:
For storing preferences in Java ME, the RecordStore class is to be used.
Ill as him to take a look at this page.

Quote:
I cannot get the exact scenario of his requirement.
requirement is simple, read two values from two textboxes and store it somewhere for future use. retrive the two values when every needed.


Quote:
Originally Posted by mastermunj View Post
Try this

But it requires JSR-75. If its not available and you do not have to store huge data.. solution suggested by chandru.in is a better option...
Thanks for the link , This is indeed usefull for him in other cases.

@Chandru: Im am still curious about storing the values in a XML file and reading it .. I read somewhere that J2ME does support it.
__________________
i5 2400 | DH67BL | G.Skill Ripjaw 4 GB | FSP SAGA II 500W | CM 430 Black Elite | MSI R6850 Cyclone PE/OC | XBox 360 Controller | 21.5" Samsung Sync Master 2233 | 4 Mbps @75GB FUP :)
Battlefield 3 Multiplayer Discussion | Battlefield 3 Low Latency Servers List
Charan is online now  
Old 10-10-2008, 06:20 PM   #5 (permalink)
CAFEBABE
 
chandru.in's Avatar
 
Join Date: Mar 2008
Location: Bangalore
Posts: 474
Default Re: File IO in J2ME

Quote:
Originally Posted by Charan View Post
Thanks for the link , This is indeed usefull for him in other cases.
JSR-75 is the one providing FileConnection class and many devices do not support it.

Quote:
Originally Posted by Charan View Post
@Chandru: Im am still curious about storing the values in a XML file and reading it .. I read somewhere that J2ME does support it.
AFAIK Java ME doesn't support XML parsing as a part of the standard. There are XML parsers for Java ME though.

For such a simple requirement, XML would be an overkill. XML processing is pretty costly on resources. Many devices may not have enough resources. Also using XML file is no different from normal file and again problems with File I/O come into scene. RecordStore class is a standard class and devices can implement it in any way they want without the Java ME developers having to worry about the implementation details.
__________________
Chandru

http://tuxychandru.blogspot.com
chandru.in is offline  
Old 10-10-2008, 06:22 PM   #6 (permalink)
Rubik's Uncle!!
 
Charan's Avatar
 
Join Date: Sep 2004
Location: ಬೆಂಗಳೂರು (Bengaluru)
Posts: 3,786
Default Re: File IO in J2ME

^^ can I get some simple examples which suites the requirement using the RecordStore
__________________
i5 2400 | DH67BL | G.Skill Ripjaw 4 GB | FSP SAGA II 500W | CM 430 Black Elite | MSI R6850 Cyclone PE/OC | XBox 360 Controller | 21.5" Samsung Sync Master 2233 | 4 Mbps @75GB FUP :)
Battlefield 3 Multiplayer Discussion | Battlefield 3 Low Latency Servers List
Charan is online now  
Old 10-10-2008, 06:26 PM   #7 (permalink)
CAFEBABE
 
chandru.in's Avatar
 
Join Date: Mar 2008
Location: Bangalore
Posts: 474
Default Re: File IO in J2ME

http://www.java2s.com/Code/Java/J2ME...ecordstore.htm
__________________
Chandru

http://tuxychandru.blogspot.com
chandru.in is offline  
Old 10-10-2008, 07:07 PM   #8 (permalink)
Rubik's Uncle!!
 
Charan's Avatar
 
Join Date: Sep 2004
Location: ಬೆಂಗಳೂರು (Bengaluru)
Posts: 3,786
Default Re: File IO in J2ME

^^ Thanks for the link. This should do that trick.
few queries.
Where exactly is the file stored? in the example record name is db_1 where is it stored?.
he is using netbeans for testing (emulation) , and a WinMo & SE K320i as test mobiles.
__________________
i5 2400 | DH67BL | G.Skill Ripjaw 4 GB | FSP SAGA II 500W | CM 430 Black Elite | MSI R6850 Cyclone PE/OC | XBox 360 Controller | 21.5" Samsung Sync Master 2233 | 4 Mbps @75GB FUP :)
Battlefield 3 Multiplayer Discussion | Battlefield 3 Low Latency Servers List
Charan is online now  
Old 10-10-2008, 07:12 PM   #9 (permalink)
CAFEBABE
 
chandru.in's Avatar
 
Join Date: Mar 2008
Location: Bangalore
Posts: 474
Default Re: File IO in J2ME

Quote:
Originally Posted by Charan View Post
Where exactly is the file stored? in the example record name is db_1 where is it stored?.
he is using netbeans for testing (emulation) , and a WinMo & SE K320i as test mobiles.
RecordStore abstracts the implementation completely from the developer. Device manufacturers can implement RecordStore in anyway they want. In fact it may not even be a file. It may even be stored in magical air space within the device.

Java ME (just like Java EE) gives only the specifications and applications are built to those specifications. How the implementation is done is completely upto the vendors.
__________________
Chandru

http://tuxychandru.blogspot.com
chandru.in is offline  
Old 10-10-2008, 07:36 PM   #10 (permalink)
Rubik's Uncle!!
 
Charan's Avatar
 
Join Date: Sep 2004
Location: ಬೆಂಗಳೂರು (Bengaluru)
Posts: 3,786
Default Re: File IO in J2ME

This is getting interesting post by post....
I am not a java developer but still im interested to give it a try
My weekend plan is fixed
__________________
i5 2400 | DH67BL | G.Skill Ripjaw 4 GB | FSP SAGA II 500W | CM 430 Black Elite | MSI R6850 Cyclone PE/OC | XBox 360 Controller | 21.5" Samsung Sync Master 2233 | 4 Mbps @75GB FUP :)
Battlefield 3 Multiplayer Discussion | Battlefield 3 Low Latency Servers List
Charan is online now  
Old 10-10-2008, 07:45 PM   #11 (permalink)
CAFEBABE
 
chandru.in's Avatar
 
Join Date: Mar 2008
Location: Bangalore
Posts: 474
Default Re: File IO in J2ME

Welcome to the wonderful land of Java. Java indeed rocks!
__________________
Chandru

http://tuxychandru.blogspot.com
chandru.in is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Books for J2ME Pathik Programming 4 12-08-2008 07:28 AM
Best J2ME IDE Charan Programming 3 01-08-2008 08:16 PM
help in J2ME Jawahar Programming 4 18-11-2007 11:32 PM
Does any one know about J2ME???................... digant_goyal QnA (read only) 1 24-01-2006 09:41 PM
J2ME or J2EE? vickymustdie QnA (read only) 7 02-03-2005 07:24 PM

 
Latest Threads
- by Sujeet
- by gforz
- by soumya

Advertisement




All times are GMT +5.5. The time now is 03:15 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2