By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,919 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,919 IT Pros & Developers. It's quick & easy.

J2ME, reading data from a text file

P: 2
I am new to J2ME programming. I finally got a program transferred to my Sony Ericsson w300i phone, installed, and running. I copied the .jar and .jad files to my "Other" folder, and installed it into the "Applications" folder. It runs.

But what I really want to do is now transfer a text data file to the phone periodically, and have the program read data from that file. I have transferred the text file to the "Other" folder, but I am not able to read from the file. I have tried:


FileConnection fc = (FileConnection)
Connector.open("file:///c:/text.txt",Connector.READ);

FileConnection fc = (FileConnection)
Connector.open("file:///c:/other//text.txt",Connector.READ);

FileConnection fc = (FileConnection)
Connector.open("file:///c:/Other//text.txt",Connector.READ);


and many other combinations. I keep getting a SecurityException. I think that I just don't know where to put the text file, or how to refer to it, but there could be some other permissions problem that I don't know about.

Unfortunately, the documentation on all of this is not good. I surely appreciate any help that anyone can provide.

Rodney Pearson
rodney.pearson@msstate.edu
Oct 12 '06 #1
Share this Question
Share on Google+
3 Replies


P: 2
More information on my request, in case anyone can help, because I am still spending hours on this and making little progress.

I have specified the desired permissions in my .jad file:

MIDlet-Permissions:
javax.microedition.io.Connector.file.read,
javax.microedition.io.Connector.file.write

(all on one line, split here only for readability).

I still get SecurityException. I have tried FileSystemRegistry.listRoots() to get the names of my root directories, but I get a SecurityException on that also.

I installed the PDAPDemo program that comes with the Sony Ericsson software, and it also encounters a SecurityException error. Even their own demo software is not working.

So far, Sony Ericsson has provided no help. I hope that someone out there can.
Oct 13 '06 #2

P: 1
I am new to J2ME programming. I finally got a program transferred to my Sony Ericsson w300i phone, installed, and running. I copied the .jar and .jad files to my "Other" folder, and installed it into the "Applications" folder. It runs.

But what I really want to do is now transfer a text data file to the phone periodically, and have the program read data from that file. I have transferred the text file to the "Other" folder, but I am not able to read from the file. I have tried:


FileConnection fc = (FileConnection)
Connector.open("file:///c:/text.txt",Connector.READ);

FileConnection fc = (FileConnection)
Connector.open("file:///c:/other//text.txt",Connector.READ);

FileConnection fc = (FileConnection)
Connector.open("file:///c:/Other//text.txt",Connector.READ);


and many other combinations. I keep getting a SecurityException. I think that I just don't know where to put the text file, or how to refer to it, but there could be some other permissions problem that I don't know about.

Unfortunately, the documentation on all of this is not good. I surely appreciate any help that anyone can provide.

Rodney Pearson
rodney.pearson@msstate.edu

Might be possible that u have not set the permissions to read or write the file
First set the permissions from Toolkit>>Settings>>Permissions
the save the file u want to read in root directory
my root directory is at C:\WTK25\appdb\DefaultColorPhone\filesystem\root1
and then try this
FileConnection fc = (FileConnection)
Connector.open("file:///root1/filename.extension",Connector.READ);
.
Nov 2 '06 #3

P: 1
Might be possible that u have not set the permissions to read or write the file
First set the permissions from Toolkit>>Settings>>Permissions
the save the file u want to read in root directory
my root directory is at C:\WTK25\appdb\DefaultColorPhone\filesystem\root1
and then try this

You can try this too. It is for a file copy on the local mobile
FileConnection fc = (FileConnection)
Connector.open("file:///root1/filename.extension",Connector.READ);
.
FileConnection fci = (FileConnection)Connector.open("file:///" + oldName);
FileConnection fco = (FileConnection)Connector.open("file:///" + currDirName + newName);
fco.create();

InputStream is = fci.openInputStream();
byte b[] = new byte[1];
int length = is.read(b);
int ch;
OutputStream os = fco.openOutputStream();
for(int i=0;i<fci.fileSize();i++)
{
if((ch = is.read())!= -1)
os.write(ch);
}
os.close();
is.close();
Dec 4 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.