Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
javec
Posts: 445
Registered: ‎07-15-2008
My Device: Not Specified

Write text to .txt file on memory card

Hello,

I am trying to write/append text to a file on the memory card:

 

 

public void createFile(){ String str = "Test"+"\n"; try { FileConnection fconn = (FileConnection)Connector.open("file:///test.txt",Connector.WRITE); if (!fconn.exists()){ //write str to the test.txt file } } catch (Exception ex){ } }

 But only creating the txt file does not do the job. Do I have to use the/a input stream? If so, how do I do that?

 

Thank you for help! 

 

 

If your question was answered, please accept it as a sollution and / or give Kudos ;-)
______________________________
Use the Search Field first! Maybe the question you want to ask already exists!
Developer
Developer
rab
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: Write text to .txt file on memory card

First check the path " file:///test.txt". This may not be correct. You need to specify the media you are writing to.

For example the SDCard will be " file:///SDCard/test.txt".

 

 

Developer
javec
Posts: 445
Registered: ‎07-15-2008
My Device: Not Specified

Re: Write text to .txt file on memory card

Hello, I actually meant the way to write a .txt file on a memory card. Lets say I have the String str = "This should be written to the card" and I want that String to be appended to a test.txt file on the media card. Can anyone help me on this?
If your question was answered, please accept it as a sollution and / or give Kudos ;-)
______________________________
Use the Search Field first! Maybe the question you want to ask already exists!
Developer
KeniF
Posts: 131
Registered: ‎08-13-2008
My Device: Not Specified

Re: Write text to .txt file on memory card

[ Edited ]

Well I believe you have to put some code in there:

 

if (!fconn.exists()){
//write str to the test.txt file
}

 

 which is

 

OutputStream os=fconn.openOutputStream();
String myString="asopdaposdkaposd";
os.write(myString.getBytes());
//Something like that - you get the idea

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/customview.html?func=...

 

There are samples in the knowledge base, use your searching skills!

By the way, learn to read the API (!)

Message Edited by KeniF on 09-15-2008 09:56 AM