Internal Storage - FileConnection fc = (FileConnection)Connector.open("file:///Store")
External Storage - FileConnection fc = (FileConnection)Connector.open("file:///SDCard")
Creating a folder-
try
{
FileConnection fc = (FileConnection)Connector.open(
"file:///SDCard/myfolder/");
if (!fc.exists())
{
fc.mkdir();
}
fc.close();
}
catch (IOException ioe)
{
System.out.println(ioe.getMessage() );
}
Creating a file -
try
{
FileConnection fc =
(FileConnection)Connector.open(
"file:///store/home/user/newfile.txt");
if (!fc.exists())
{
fc.create();
}
fc.close();
}
catch (IOException ioe)
{
System.out.println(ioe.getMessage() );
}
Writing text to a file -
try
{
FileConnection fc = (FileConnection)Connector.open(
"file:///store/home/user/newfile.txt");
if (!fc.exists())
{
fc.create();
}
OutputStream outStream = fc.openOutputStream();
outStream.write("test content".getBytes());
outStream.close();
fc.close();
}
catch (IOException ioe)
{
System.out.println(ioe.getMessage() );
}
No comments:
Post a Comment