hi.........
i want to create a directory in mobile using j2me. I don't know the exect way to do it. any body pls give me the code how to create a directory.
hi.........
i want to create a directory in mobile using j2me. I don't know the exect way to do it. any body pls give me the code how to create a directory.
Have a look at API docs.
Regardsmkdir
public void mkdir()
throws java.io.IOException
Creates a directory corresponding to the directory string provided in the Connector.open() method. The directory is created immediately on the actual file system upon invocation of this method. Directories in the specified path are not recursively created and must be explicitly created before subdirectories can be created.
Throws:
java.lang.SecurityException - if the security of the application does not have write access to the directory.
IllegalModeException - if the application does have write access to the directory but has opened the connection in Connector.READ mode.
java.io.IOException - if invoked on an existing directory or on any file (create() is used to create files), the target file sytem is not accessible, or an unspecified error occurs preventing creation of the directory.
ConnectionClosedException - if the connection is closed.
Gopal
__________________
MobiQuil.com
An initiative by Developers for Developers.
http://www.mobiquil.com - Alpha - Launched.
hi..........
Now the directory is created but i m not able to display it with the list of Directories.....either on memory card or on C:\ drive......
if you can help me on this pls....
susha
public java.util.Enumeration list()
throws java.io.IOException
Gets a list of all visible files and directories contained in a directory. The directory is the connection's target as specified in Connector.open().
Returns:
An Enumeration of strings, denoting the files and directories in the directory. The string returned contain only the file or directory name and does not contain any path prefix (to get a complete path for each file or directory, prepend getPath()). Directories are denoted with a trailing slash "/" in their returned name. The Enumeration has zero length if the directory is empty. Any hidden files and directories in the directory are not included in the returned list. Any current directory indication (".") and any parent directory indication ("..") is not included in the list of files and directories returned.
Throws:
java.io.IOException - if invoked on a file, the directory does not exist, the directory is not accessible, or an I/O error occurs.
ConnectionClosedException - if the connection is closed.
java.lang.SecurityException - if the security of the application does not have read access for the directory.
IllegalModeException - if the application does have read access to the directory but has opened the connection in Connector.WRITE mode.Also have a look at listRoots()public java.util.Enumeration list(java.lang.String filter, boolean includeHidden)
throws java.io.IOException
Gets a filtered list of files and directories contained in a directory. The directory is the connection's target as specified in Connector.open().
Parameters:
filter - String against which all files and directories are matched for retrieval. An asterisk ("*") can be used as a wildcard to represent 0 or more occurrences of any character.
includeHidden - boolean indicating whether files marked as hidden should be included or not in the list of files and directories returned.
Returns:
An Enumeration of strings, denoting the files and directories in the directory matching the filter. Directories are denoted with a trailing slash "/" in their returned name. The Enumeration has zero length if the directory is empty or no files and/or directories are found matching the given filter. Any current directory indication (".") and any parent directory indication ("..") is not included in the list of files and directories returned.
Throws:
java.io.IOException - if invoked on a file, the directory does not exist, the directory is not accessible, or an I/O error occurs.
ConnectionClosedException - if the connection is closed.
java.lang.SecurityException - if the security of the application does not have read access for the directory.
IllegalModeException - if the application does have read access to the connection's target but has opened the connection in Connector.WRITE mode.
java.lang.NullPointerException - if filter is null.
java.lang.IllegalArgumentException - if filter contains any path specification or is an invalid filename for the platform (e.g. contains characters invalid for a filename on the platform).
An online version of API docs is available here http://www.j2medev.com/api/fileconne...w-summary.html
Regards
Gopal
__________________
MobiQuil.com
An initiative by Developers for Developers.
http://www.mobiquil.com - Alpha - Launched.
Hi,
I have written an application for file access.I able to write & read from file but how can I append text to a file ?
My code is like that for connection:
connection=(OutputConnection)Connector.open("file:///root1/myfile9.txt;append=true", Connector.WRITE);
java.io.IOException:
at com.sun.midp.io.j2me.file.Protocol.openOutputStream(+47)
at com.sun.midp.io.j2me.file.Protocol.openOutputStream(+5)
at File_Append$FileForm.run(+35)
But if I omit this append=true; portion then Its working fine & data is written to the file.
Can anybody tell me how can I append data to a file ,It is so urgent!
Thanks in advance.
hi...
I have created a directory, i created it in root1(using j2me toolkit) .
again i changed the path(/SDCard/name)and instald te application in to mobile(N72).But now it is not working.It shows Error(Exception). pls tell me the correct way to work this application in mobile.. Need any more change in the path?
Thanks in advance.
susha
I suggest you to go through the Blog
"FileConnection - Introduction to beginners"
https://blogs.forum.nokia.com/view_entry.html?id=131
Also please dont forget to go through "MIDP: FileConnection API Developer's Guide (with Example) v2.0"
http://www.forum.nokia.com/info/sw.n..._0_en.zip.html
Hope this shoot out all your problems!
Regards
Gopal
__________________
MobiQuil.com
An initiative by Developers for Developers.
http://www.mobiquil.com - Alpha - Launched.
hi,
i checked these link,in that they specified the path (/SDCard).but i tried it in my mobile.but it shows error again.Is there need any more changes in code?
regards
susha
Hello gopal,
i m using the following codes to create a directory in images folder ..
String initDir = System.getProperty("fileconn.dir.photos")+"new";
//String path=System.getProperty("Fileconn.dir.photos")+"new";
fmMain.append(initDir);
try {
FileConnection fc=(FileConnection)Connector.open(initDir,Connector.WRITE);
if(!fc.exists())
{
fc.mkdir();
Alert alert1 = new Alert("dir CREATION Completed", "Data Written", null, null);
alert1.setTimeout(Alert.FOREVER);
fc.close();
}
but i will get a "SecurityException"
so plz sugest any perticular mobile for that..to create ..i m also given the permission to to Fileconnection.read,Fileconnection.write ..but i get thye same error ....plz reply anyone
Hi arunoosy! Welcome to Nokia Discussion Boards!!![]()
Hope your phones does suupport JSR 75. Is your phone an operator branded one? Is your MIDlet signed?
Please make sure that you allow the permission messages popping up.
Regards
Gopal
__________________
MobiQuil.com
An initiative by Developers for Developers.
http://www.mobiquil.com - Alpha - Launched.
Iam using the n72 mobile.I can reading the file,but i can't create the directory,it shows no permission.how to resolvr this permission error?
Try with canWrite()Originally Posted by susha
Regardspublic boolean canWrite()
Checks if the file or directory is writable. This method checks the attributes associated with a file or directory by the underlying file system. Some file systems may not support associating a write attribute with a file, in which case this method returns true.
Returns:
true if the connection's target exists, is accessible, and is writable, otherwise false.
Throws:
java.lang.SecurityException - if the security of the application does not have read access for the connection's target.
IllegalModeException - if the application does have read access to the connection's target but has opened the connection in Connector.WRITE mode.
ConnectionClosedException - if the connection is closed.
Gopal
__________________
MobiQuil.com
An initiative by Developers for Developers.
http://www.mobiquil.com - Alpha - Launched.
hiiiiiiiiiii...........
pls tell me anyone have created a directory in mobile.pls tell me in which nokia set.i want these details urgent...please help me.
is it possible in N72.
regards
susha
i have created a directory in nokia 6680 i dont know about N72
Regards
Nouman
I tried the following code on my friends N93 and it worked fine.Originally Posted by susha
I have never tried with N72, hopefully, this will work fine with N72 as well.fc = (FileConnection)Connector.open("file:///c:/Nokia/Sounds/TestDIR/");
if (!fc.exists()) {
fc.mkdir();
}
Regards
Gopal
__________________
MobiQuil.com
An initiative by Developers for Developers.
http://www.mobiquil.com - Alpha - Launched.