List of all Iphone and Blackberry Development codes in a one click Iphone,objective C,xcode,blackberry Development,iOS Development

Thursday, June 27, 2013

Creating Folder on SD Card in Blackberry

The File Connection API is implemented in the javax.microedition.io.file package.
Internal Storage - FileConnection fc = (FileConnection)Connector.open("file:///Store")
External Storage - FileConnection fc = (FileConnection)Connector.open("file:///SDCard")

Creating a folder-

try 
        {    
             FileConnection fc = (FileConnection)Connector.open(
"file:///SDCard/myfolder/");
             if (!fc.exists())
             {
                 fc.mkdir(); 
             }
             fc.close();
         }
         catch (IOException ioe) 
         {
            System.out.println(ioe.getMessage() );
         }
 

Creating a file - 

 try 
      {
          FileConnection fc = 
               (FileConnection)Connector.open(
"file:///store/home/user/newfile.txt");
          if (!fc.exists())
          {
              fc.create();  
          }
          fc.close();
       }
       catch (IOException ioe) 
       {
          System.out.println(ioe.getMessage() );
       }
 

Writing text to a file - 

try 
    {
      FileConnection fc = (FileConnection)Connector.open(
"file:///store/home/user/newfile.txt"); 
      if (!fc.exists())
      {
          fc.create();  
      }
      OutputStream outStream = fc.openOutputStream(); 
      outStream.write("test content".getBytes());
      outStream.close();
      fc.close();
     }
     catch (IOException ioe) 
     {
        System.out.println(ioe.getMessage() );
     }
 

No comments:

Post a Comment