Hi all,
I want to create a file on device and read that file,I had written the code
but,I don't know where I went wrong.
I had used the following code:
To creat file Code:
FileConnection fconn = (FileConnection)Connector.open("file:///SDCard/testfile.txt");
// If no exception is thrown, then the URI is valid, but the file may or may not exist.
if (!fconn.exists())
fconn.create(); // create the file if it doesn't exist
FileOutputStream fileOutputStream = new FileOutputStream(1,"file:///SDCard/testfile.txttestfile.txt");
String str="welcome to funnyworld";
byte[] data=str.getBytes() ;
String datafromServer= data.toString();
int length = datafromServer.length();
fileOutputStream.write(data, 0, length);
fileOutputStream.close();
fconn.close(); To read the file Code:
FileInputStream fileInputStream=new FileInputStream(1,"file:///SDCard/testfile.txt") ;
while(true)
{
int val=fileInputStream.read();
if(val==-1)
break;
else
{
_mainScreen.add(new LabelField(""+fileInputStream.read()));
}
}
fileInputStream.close(); can anyone suggest me the proper solution
I got another Question
Can we see the created file on the device?
Thanks,
Dinesh