Connecting Tech Pros Worldwide Help | Site Map

J2ME, reading data from a text file

  #1  
Old October 12th, 2006, 10:16 PM
Newbie
 
Join Date: Oct 2006
Posts: 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
  #2  
Old October 13th, 2006, 06:24 PM
Newbie
 
Join Date: Oct 2006
Posts: 2

re: J2ME, reading data from a text file


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

re: J2ME, reading data from a text file


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);
.
  #4  
Old December 4th, 2007, 02:04 AM
Newbie
 
Join Date: Dec 2007
Posts: 1

re: J2ME, reading data from a text file


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
.Net frameword Resources ( vb.net , asp.net etc...) shamirza answers 0 January 17th, 2007 08:05 AM
Starting University COSC and learning JAVA, advice please :D David Van D answers 1 February 4th, 2006 02:45 AM