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

AS-IS Lot of 4 Cisco CP-7942G IP VoIP Business Office Phone w/oHandsets-Cordset
$7.99
AS-IS Lot of 4 Cisco CP-7942G IP VoIP Business Office Phone w/oHandsets-Cordset picturePolycom CX300 R2 USB VoIP Microsoft Lync Skye for Business Office Desktop Phone
$88.0
Polycom CX300 R2 USB VoIP Microsoft Lync Skye for Business Office Desktop Phone pictureAS-IS Cisco IP Phone 7961 Series CP-7961G Voip Business Phone
$5.99
AS-IS Cisco IP Phone 7961 Series CP-7961G Voip Business Phone pictureNEW Nortel Avaya BCM 400 BCM400 4.0 R4 Base System Standard NT7B10AAFRE5 VoIP IP
$995.0
NEW Nortel Avaya BCM 400 BCM400 4.0 R4 Base System Standard NT7B10AAFRE5 VoIP IP pictureJDSU HST-3000 VoIP SIM E1 Handheld Services Tester
$1500.0
JDSU HST-3000 VoIP SIM E1 Handheld Services Tester picture






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