BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-25-2008, 08:58 PM   #1 (permalink)
New Member
 
Join Date: Oct 2008
Model: 8310
PIN: N/A
Carrier: Indosat
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Create file xml, succeessful on simulator but failed on device

Please Login to Remove!

Hi all,

i am trying to create file xml on SDCard. It is successful on simulator but when i deploy the app to device, the file creation failed. Does any body know how to solve it or something wrong with my code ?

Note that my app has been signed with RRT, RBB, RCR

here is part of my code :

private String sdCard = "file:///SDCard/BlackBerry/";
private boolean fileExists;

public void open(String fileName) throws Exception{
this.fileName = fileName;
fConn = (FileConnection)Connector.open(sdCard+fileName, Connector.READ_WRITE);
this.fileExists = fConn.exists();
}

public void write(String content) throws Exception{
if(fileExists){
fConn.delete();
}
fConn.create();
fConn.setWritable(true);
outStream = fConn.openOutputStream();
outStream.write(content.getBytes());
//outStream.flush();
}

public boolean fileExists(){
return fileExists;
}
Offline  
Old 11-25-2008, 11:24 PM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2006
Location: TX
Model: 8700g
Carrier: TMO
Posts: 27
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

is your application signed?

BlackBerry - Java Code Signing Keys
Offline  
Old 11-25-2008, 11:32 PM   #3 (permalink)
New Member
 
Join Date: Oct 2008
Model: 8310
PIN: N/A
Carrier: Indosat
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes it is. I had stated it at my first post.
Offline  
Old 11-26-2008, 05:18 AM   #4 (permalink)
Knows Where the Search Button Is
 
robinShazam's Avatar
 
Join Date: Oct 2008
Location: london, uk
Model: 8120
OS: 4.3.0.67
PIN: N/A
Carrier: Lots
Posts: 15
Post Thanks: 0
Thanked 0 Times in 0 Posts
Arrow

Do you get any exceptions?

Is the card write-protected (some have that cheeky little write-protector switch on them.)

Does the folder "Blackberry" exist on the sd card? (it will not be created automatically.)

Can you at least read from the card? I use the function below to scan all folders and report them - see if that works for you. Apologies for the slack string appending!

Code:
...
scanFolder( "SDcard/", 0 );
...
...


	private void scanFolder( String path, int deep ){
		FileConnection fc = null;
    	
		try{
			fc = (FileConnection)Connector.open( "file:///" + path );
			Enumeration fl = fc.list();
			while( fl.hasMoreElements() ){
				String file = (String)fl.nextElement();

				boolean bDir = false;
				FileConnection fd = (FileConnection)Connector.open( "file:///" + path + file );
				try{
					bDir = fd.isDirectory();
				}finally{
					try{ fd.close(); }catch( Throwable th ){ ; }
					fd = null;
				}

				if (bDir){
					StringBuffer sb = new StringBuffer();
					int i = 0; 
					while( i++ <= deep ) sb.append( "  " );
					sb.append( file );
					// report directory name here

					scanFolder( path + file, deep+1 );
				}
			}

		}catch( IOException ioe ){
			// report ioe here

		}catch( SecurityException se ){
			// report se here

		}catch( Throwable th ){
			// report th here

		}finally{
			if (fc != null){
				try{ fc.close(); }catch( Throwable th ){ ; }
				fc = null;
			}
		}
	}
Offline  
Old 12-03-2008, 10:40 PM   #5 (permalink)
New Member
 
Join Date: Oct 2008
Model: 8310
PIN: N/A
Carrier: Indosat
Posts: 10
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi robinShazam,

The exception message is 'File system error'. Do you have any idea ?


thx,

Vis'
Offline  
Old 12-04-2008, 01:17 AM   #6 (permalink)
New Member
 
Join Date: Nov 2008
Model: 8310
PIN: N/A
Carrier: no
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

public void write(String content) throws Exception{
if(fileExists){
fConn.delete();
// reopen
}
fConn.create();
}

After deleting a file, you have to reopen file connection.
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.