Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 2726 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.

Offline JasonB

Junior Devvie

« 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 Ninja

Medals: 66

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.
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 - 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
Offline davidaprice

Junior Devvie

« 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 Devvie

Java games rock!

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

check out the oct articl eon you can do file acces through access memory cards and thelike..

Pages: [1]
  ignore  |  Print  

EgonOlsen (79 views)
2018-06-10 19:43:48

EgonOlsen (59 views)
2018-06-10 19:43:44

EgonOlsen (78 views)
2018-06-10 19:43:20

DesertCoockie (261 views)
2018-05-13 18:23:11

nelsongames (159 views)
2018-04-24 18:15:36

nelsongames (158 views)
2018-04-24 18:14:32

ivj94 (901 views)
2018-03-24 14:47:39

ivj94 (162 views)
2018-03-24 14:46:31

ivj94 (813 views)
2018-03-24 14:43:53

Solater (177 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!