BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-25-2007, 02:40 PM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Model: 8100
PIN: N/A
Carrier: movistar
Posts: 51
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default FileConnection

Please Login to Remove!

I need create a file .txt in one directory of my blackberry.
Somebody have a exmple.

i have this:

public void createFile() {
long largo = 0;
String url = "file:///myfile.txt";
FileConnection conn = null;

try {
conn = (FileConnection) Connector.open( url,
Connector.READ_WRITE );
if( !conn.exists() ){ // create the file
System.out.println("No existe archivo");
// conn.create();
// OutputStream out = conn.openOutputStream();
// now write data to the file
}

conn.close();
}
catch( IOException e ){
System.out.println("ERROR 1 : " + e.toString());
}
catch( SecurityException e ){
System.out.println("ERROR 2 : " + e.toString());
}

}


but request this error :

CodeStore.DependencyList.buildModuleDependencyList () took 16 - [16]
ERROR 1 : net.rim.device.api.io.file.FileIOException: File system error

help me , thanks
Offline  
Old 07-26-2007, 03:13 AM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

As far as i know the path where you want to store the file is not correct...you can store it to the card or into the phone memory...if you want to store it in the SDcard the path should be like that:

"file:///SDCard/myfile.txt"

I don't how it is on the phone memory...it depends on the phone...for 8100 it is like this... "file:///store/myfile.txt"...or you should see the tree on the phone using FileConnection list() method...hope this will help you
Offline  
Old 07-30-2007, 12:08 PM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Model: 8100
PIN: N/A
Carrier: movistar
Posts: 51
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default File to binary

hello thanks
a need transform a File to binary for post to data base whit httpconnection
plis help me.
thanks
Offline  
Old 07-31-2007, 02:48 AM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I read the content of a image file like .jpeg file with that code..it is working...

Code:
public byte[] readImage(String fileName) {
    byte[] image = null;
    try {
      fconn = (FileConnection) Connector.open(fileName);
      if (!fconn.exists()) {
        fconn.create();
      }
      DataInputStream is = fconn.openDataInputStream();
      image = new byte[(int) fconn.fileSize()];
      is.readFully(image, 0, image.length);
      is.close();
    } catch (Exception e) {
      Dialog.alert("Exception: " + e);
    }
    return image;
  }
..after that you should transform this byte array as binary array or something like that....i don't know how it is working properly...hope s.o. else will help you
Offline  
Old 07-31-2007, 10:50 AM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Model: 8100
PIN: N/A
Carrier: movistar
Posts: 51
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Directory

thanks,
Now, iŽneed read a directory and see in a choice field all files in this directory.
pleas, if you have a code example.
Offline  
Old 07-31-2007, 11:15 AM   #6 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

So i used that code...it is to get all the system ringtones names and put them in BorderChoiceField....

Code:
private List getRingtones() {
    List ringtones = new ArrayList();
    Enumeration ringtonesNames = null;
    try {
      FileConnection fc = (FileConnection) Connector.open("file:///store/samples/ringtones/"); 
      ringtonesNames = fc.list();
    } catch(IOException e) {
      Dialog.alert("Exception:" + e);
    }
    while(ringtonesNames.hasMoreElements()) {
      String sound = (String) ringtonesNames.nextElement();
      ringtones.add(sound);
    }
    return ringtones;
  }
and then you just put the names from List to array ot String objects because the constructor ot BorderChoiceField needs String objects array...

Code:
String choiceItems[] = new String[ringtones.size()];
......//need put the names from ringtones (ArrayList) in the choiceItems (String[])
BorderChoiceField sounds = new BorderChoiceField("", choiceItems);
Hope you understand me...Bye
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright © 2004-2014 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.