Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Local File I/O - is it possible?  (Read 1500 times)
0 Members and 1 Guest are viewing this topic.
Offline mhnsp

Junior Newbie




Java games rock!


« Posted 2003-11-26 12:35:23 »

There is probably a simple answer to this problem, but I'll ask anyway.

Is there any way to do local file i/o in J2ME?  Specifically, I am wanting to access a data file packaged in my JAR file.  J2ME does not support Properties or ResourceBundles, and I tried to do:

DataInputStream dis = Connector.openDataInputStream("file://xyz");

... but it gave me a non-supported protocol exception.

Thanks.
Offline JasonB

Junior Duke





« Reply #1 - Posted 2003-11-26 16:51:28 »

Off the top of my head, I think it's device/manufacturer specific.  A manufacturer can offer other connectors but is under no obligation to do so.  So even if you had that facility, you might not want to use it if you're trying to target a number of phones.

That said, if you're trying to get something out of the jar, maybe you can call

DataInputStream dis = new DataInputStream(this.getClass().getResourceAsStream("myresource"));

But I can't recall ever doing this, so hopefully someone else can confirm.
Offline Abuse

JGO Knight


Medals: 13


falling into the abyss of reality


« Reply #2 - Posted 2003-11-27 10:58:42 »

yeah, the getResourceAsStream() works fine for reading from the jar.

As for storage, that is what the rms package is for.

Some manufacturers do provide ways to write directly to files, but as said earlier, it makes your code platform dependant.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline huiben

Senior Newbie




Mobile Guru


« Reply #3 - Posted 2003-11-27 20:14:12 »

Siemens and some motorola (e.g. i730) provide file access. i believe some japanese phone (iAppli..) has file access as well. otherwise, nothing in the standard spec

ben

www.benhui.net - mobile developer resources - j2me - links - bluetooth - device and more!

Get Travel Buddy - Itinerary, Tracker, Global Clock, Currency Convertor - 4-in-1
Free version available at http://www.sklogicsoftware.com
Offline davidaprice

Junior Duke





« Reply #4 - Posted 2003-11-28 05:26:11 »

JasonB is right: in the special case of reading a file in your MIDlet's JAR, you should use getResourceAsStream. It's actually the same thing as when you use Image.createImage("/myfile.png") - that's also reading a file from the JAR, and is typically implemented using getResourceAsStream.

As with Image.createImage, you probably want to start the file name with "/", otherwise it'll look for the resource in a directory based on the class's package name.

If you want to read some other local file in the phone, you'll have to wait for phones which implement the JSR-75 File API, or use some proprietary API if the phone you target has one.
Offline mhnsp

Junior Newbie




Java games rock!


« Reply #5 - Posted 2003-12-01 11:21:13 »

Great.  Thanks everyone.  Never thought about using getResourceAsStream().  I'll give it a try.
Offline shareme

Junior Duke




Java games rock!


« Reply #6 - Posted 2003-12-03 21:49:38 »

check out the oct articl eon wireless.java.com you can do file acces through gcf..ie access memory cards and thelike..


Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!