BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 06-01-2007, 10:05 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Feb 2007
Location: India
Model: 7100v
Carrier: aittel
Posts: 35
Post Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Regarding file storage on device

Please Login to Remove!

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
Offline  
Old 06-13-2007, 02:01 AM   #2 (permalink)
Thumbs Must Hurt
 
Rose's Avatar
 
Join Date: Nov 2006
Location: India
Model: 9700
OS: Windows 7
Carrier: Airtel
Posts: 121
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
From the api FileInputStream and FileOutputStream can be used to open Iden file system only.. If you want to create file in SDCard you should use the javax.microedition.io.file classes and normal inputstream and outputStream.
I hope that will do for you.
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

LOT of 12 GENUINE OEM IBM EASYSTRIKE LIFT OFF TAPE CASSETTES #1337765
$40.0
LOT of 12 GENUINE OEM IBM EASYSTRIKE LIFT OFF TAPE CASSETTES #1337765  pictureIBM 1337761 Genuine OEM Easystrike Correctable Ribbon Cassette - New Old Stock
$8.95
IBM 1337761 Genuine OEM Easystrike Correctable Ribbon Cassette - New Old Stock pictureIBM 1337765 Genuine OEM Lift Off Tape Cassette - New Old Stock
$5.95
IBM 1337765 Genuine OEM Lift Off Tape Cassette - New Old Stock pictureIBM #4 Y Cable Genuine OEM Long POS Cash Register 4A to 4B 10N1002 J96367
$24.99
IBM #4 Y Cable Genuine OEM Long POS Cash Register 4A to 4B 10N1002 J96367 picture3 NEW Genuine OEM IBM Lexmark 1361190 Correctable Typewriter Ribbon NOS
$19.98
3 NEW Genuine OEM IBM Lexmark 1361190 Correctable Typewriter Ribbon NOS picture






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