• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing a local file

 
Al Brotherton
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to instantiate a InputStreamReader to a XML file stored on my device or in the Jar file. Below is a code segment I used. Any help would be appreciated.
String URL = "file:/" + sFileName;
try {
InputConnection icFile = (InputConnection) Connector.open(URL);
parser = new KXmlParser();
parser.setInput(new InputStreamReader(icFile.openInputStream()));
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, your approach would not work. You have to read the file as resource (I presume you packed it in your JAR file)
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I was hoping you would know if it would be possible to access a file on the local device that is not in the .jar file.

No, you cannot do with standard MIDP. MIDP programs have to portable across many devices. Some devices do not even have a "local filesystem" (Palm OS is an example). So, MIDP does not include an API for local file access.
However, device vendors might have their own API extension for MIDP and they might include this feature. But if use device specific features, your program will be no longer portable.
 
Timothy Toe
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Yuan, thanks for the helpful answer. I was about to ask the same question when I chanced upon your answer in this thread.
However, device vendors might have their own API extension for MIDP and they might include this feature.

Do you know whether Nokia & Siemens have thier proprietary API to access their own local file system like what you mentioned ?
Anybody knows the answer ? Pls help.
 
Timothy Toe
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, I wish to read a midi file (ring tones etc) from the local file system... and play it via my midlet with MMAPI.
Thanks.
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not think Nokia allows you to access ringtones from your MIDP app. Motorola *might* have an API for that (I think Motorola has been supporting the file I/O API for a while).
But accessing copyrighted digital content on the phone is a sensitive issue to device makers. I would not be surprise if the Motorola file I/O prohibits access to installed midi ringtone files ...
 
Timothy Toe
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yuan, thanks.
But accessing copyrighted digital content on the phone is a sensitive issue to device makers.

Yup, there're always copyright issues. But sometimes I just would like to just concentrate on the technical issues (whether possible to do this/that).
Anyway, not all midi files in the handphone are copyrighted. For example, I can create/compose my own midi composition on the PC and transfer the midi into my mobile via a data cable. And when I do this, the midi file will be in the local file system.
If MIDP/proprietery file IO API allows access to midis outside the jar file, think of the possibilities : the midi that is played could be dynamically changed by just changing the midi file in the file system (which is easy with data cable).
It is just sad that Midlets could not access the local file system. Can I say that handphone makers are narrow minded by focusing only on copyright issues ?
If midies have to be included/packaged into the jar file, then the midi a midlet can play will be sort of "hardcoded"/"fixed".
 
Timothy Toe
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add something...
Most midis downloaded via WAP/GPRS were bought anyway (this means royalty paid). So there should not be any copyright issues.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Timothy Toh:
Most midis downloaded via WAP/GPRS were bought anyway (this means royalty paid). So there should not be any copyright issues.

Well, they were bought for private use. The vendors are not worried about letting you listen to your midi tones with a custom midlet. They're worried about you copying that midi tone to your friend and your friend's friend.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And so on, and so on, and so on.
Just because they bought the rights to do something with the song, does not mean that that now gives you those same rights.
Mark
 
Timothy Toe
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this mean that we will never be able to have Mobile WinAmp ??? I mean... since we can't access the local file system. (Let us not talk about piracy and concentrate on technical.)
[ January 20, 2004: Message edited by: Timothy Toh ]
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Timothy Toh:
Does this mean that we will never be able to have Mobile WinAmp ??? I mean... since we can't access the local file system. (Let us not talk about piracy and concentrate on technical.)

Well, you *can* access the file system via the PDA optional package on MIDP. It is just not available on many devices because it is "optional" (none of the Nokia devices, for example) and because many low end devices do not have file systems at all. Also, Motorola has proprietary APIs for file system access on some models. In addition, the file I/O is always available on Personal Profile devices.
So, whether you can access the file system on a particular device is at the mercy of the device manufacturer. That is why I advocate openning the native API access on the J2ME platform -- so that any third party vendor can implement the PDA OP for Symbian MIDP phones ...
[ January 20, 2004: Message edited by: Michael Yuan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic