Connecting Tech Pros Worldwide Help | Site Map

J2ME, reading data from a text file

 
LinkBack Thread Tools Search this Thread
  #1  
Old October 12th, 2006, 09:16 PM
Newbie
 
Join Date: Oct 2006
Posts: 2
Default J2ME, reading data from a text file

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
Reply
  #2  
Old October 13th, 2006, 05:24 PM
Newbie
 
Join Date: Oct 2006
Posts: 2
Default

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.
Reply
  #3  
Old November 2nd, 2006, 09:30 AM
Newbie
 
Join Date: Nov 2006
Posts: 1
Default

Quote:
Originally Posted by rpearson
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);
.
Reply
  #4  
Old December 4th, 2007, 01:04 AM
Newbie
 
Join Date: Dec 2007
Posts: 1
Default

Quote:
Originally Posted by bharatdevda
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();
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.