J2ME Open file for writing

D

Darko

Hi to all!

At the moment I'm using the API that hasn't got FileConnection class,
so I'm using
OutputStream o = ((OutputConnection)Connector.open(
"file:///root1/file" )).openOutputStream();

I don't know if I have some typos, but it doesn't matter. It works for
files that already exist but there are several problems:
1. If the file doesn't exist, it won't create it. I saw thew way
people do it by using FileConnection, but I don't have it. What's the
way around?
2. If the file is bigger than the content I'm writing, only the part
of it is overwritten. What I would like is the "truncate" behaviour,
meaning the file should be truncated the moment it's open for writing.
3. How do I delete the file later, once I don't need it?

Thank you in advance, I'm waiting by the computer for the answer :)
[just kidding :]

Darko
 
D

Darko

Since noone has answered on my question, does anybody have an idea
where else should I put the question? Sun forum? Other Usenet group?
Somewhere else?

Thanks,

Darko

Darko wrote
 
D

ddimitrov

J2ME devices are not required to have a filesystem, hence - no standard
API. Some vendors offer custom connectors which kinda look like files
(check your vendor's docs.)

http://www.google.com/search?q=j2me connectors


The standard operational storage is the RMS:
http://www.google.com/search?q=j2me+rms

Any config files and images need to be loaded from the classpath or
downloaded from the server (AFAIR you can open a connection only to the
host from which the midlet was downloaded, but this may be an operator
restriction).
 
S

Simon Brooke

Darko said:
Hi to all!

At the moment I'm using the API that hasn't got FileConnection class,
so I'm using
OutputStream o = ((OutputConnection)Connector.open(
"file:///root1/file" )).openOutputStream();

I don't know if I have some typos, but it doesn't matter. It works for
files that already exist but there are several problems:
1. If the file doesn't exist, it won't create it. I saw thew way
people do it by using FileConnection, but I don't have it. What's the
way around?
2. If the file is bigger than the content I'm writing, only the part
of it is overwritten. What I would like is the "truncate" behaviour,
meaning the file should be truncated the moment it's open for writing.
3. How do I delete the file later, once I don't need it?

Thank you in advance, I'm waiting by the computer for the answer :)
[just kidding :]

MIDP doesn't mandate a file system; you cannot assume a file system exists
and you cannot in general write to one. If you /can/ write to something
using a 'file:///' URL I suggest that's a bug not a feature.

Personal Profile mandates a files system; if your device supports Personal
Profile you're OK. Otherwise, use RMS.
 
S

Simon Brooke

Darko said:
Since noone has answered on my question, does anybody have an idea
where else should I put the question? Sun forum? Other Usenet group?
Somewhere else?

Have patience, glasshopper. Answers will come.

In general in my experience this froup is /way/ better for J2ME questions
than any of the Sun or Nokia forums.
 
D

Darko

1. If the file doesn't exist, it won't create it. I saw thew way
people do it by using FileConnection, but I don't have it. What's the
way around?
2. If the file is bigger than the content I'm writing, only the part
of it is overwritten. What I would like is the "truncate" behaviour,
meaning the file should be truncated the moment it's open for writing.
3. How do I delete the file later, once I don't need it?

Thanks to all, it's a good set of answers to show to my employer :)
He's convinced there's a way to do it, I was (after reading the midp
documentation) there isn't but I wondered if there's a way around.
Anyways, thank's a lot, it's obvious that, yes, I should have waited a
little bit more before getting impatient.

Bye,

Darko
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top