Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (565)
Games in Android Showcase (151)
games submitted by our members
Games in WIP (606)
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 1618 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 Knight

Medals: 17

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!
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  
You cannot reply to this message, because it is very, very old.

theagentd (13 views)
2015-03-27 23:08:20

wxwsk8er (54 views)
2015-03-20 15:39:46

Fairy Tailz (47 views)
2015-03-15 21:52:20

Olo (29 views)
2015-03-13 17:51:59

Olo (30 views)
2015-03-13 17:50:51

Olo (39 views)
2015-03-13 17:50:16

Olo (44 views)
2015-03-13 17:47:07

ClaasJG (57 views)
2015-03-10 11:36:42

ClaasJG (41 views)
2015-03-10 11:33:01

Pippogeek (50 views)
2015-03-05 14:36:23
How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

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 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!