08-20-2009 03:47 AM
I want to know how to write content in file. example:I am having one basic edit field and one save button if click the save button then it should write the content of basiceditfield into one text file and i can able to retrive that file in later.Can any one tell me how to do ? If u can provide me some code snippet.
Solved! Go to Solution.
08-20-2009 04:45 AM
FileConnection fc = (FileConnection) Connector.open(System.getProperty("file:///SDCard/
"+"test.txt"),Connector.READ_WRITE); if(!fc.exists()) fc.create(); OutputStream os =fc.openOutputStream(); os.write(yourfield.getText()); os.close(); fc.close();
You can make use of read methods to read teh File content..
08-20-2009 04:47 AM
Check this thread for reading...
08-20-2009 05:37 AM
thanks for ur immediate response and in ur reply "file:///SDCard/" this location refers to where? and if it refers SDCard in blackberry means how to make it in simulator 9000.
08-20-2009 05:39 AM
Check this KB article.
08-20-2009 06:20 AM
Hi i have read and tried the article but still i m having some problem.
In my system's " E: " i created one flolder with the name " SDCard "and i have specify this location ("E:\SDCard") at PCFilesystem path for SDCard files in the prefrence window then i click ok.After that i can see one folder inside that SDCard folder with the name of blackberry and inside the blackberry folder i can see six folders with name of documents,music,picture,ringtones,videos,and voice chats.I created a file "test.txt" inside the Document folder and i specify the path as ("E:/SDCard/BlackBerry/Documents/"+"test.txt") in the FileConnection even i can get a error can u pls what i m doing wrong.
08-20-2009 06:45 AM
i have tried all the following ya still i m getting null url exception ,
1) FileConnection fc=(FileConnection)Connector.open(System.getProper
2) FileConnection fc=(FileConnection)Connector.open(System.getProper
08-20-2009 07:00 AM
FileConnection fc = (FileConnection)Connector.open("file:///SDCard/Bla
08-20-2009 07:20 AM
Hey thanks ya.Now file is creating ya but contents are not written in the file ya.
i try to write a stirng driectly in os.write(stringvalue) but it show the error then i refer the api then we can only able to write only byte and int so i convert my string in one byte array then i write into file using for loop but no content is writing ya.here is the part of the code which i have used.
OutputStream os =fc.openOutputStream();
byte barr=new byte[stringvalue.length()];