Solved

openDataOutputStream() File system error (12)

Posted on 2010-09-23
1
1,042 Views
Last Modified: 2013-12-15
the code on line "outstream = fileconn.openDataOutputStream();" (full code attached below) throws an exception with message "File system error (12)" ?

the funny thing is that the exception is not thrown the first time the WriteXml(); is called i.e. on first call during every lifetime of the application, the file writing completes successfully, but all subsequent calls after the first one fail and throw this file system error??? our application works by first reading an xml file, and then writing one (WriteXml()) if the user presses Save (which works first time), but if the user presses Save again, the writing does not work any more.

when i close the application and start it again, the first save works fine again, but not the following ones? any ideas how to solve this issue?


cheers.

import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import net.rim.device.api.ui.component.Dialog;
import org.kxml2.io.KXmlParser;
import org.kxml2.io.KXmlSerializer;
import org.kxml2.kdom.Document;
import org.kxml2.kdom.Element;
import org.kxml2.kdom.Node;

public class Filer {

	
private String filepath = "file:///SDCard/Blackberry/TelliT.xml";
	private String ip = "192.168.1.1";
	private String port = "80";

public void WriteXml() {

try {
			FileConnection fileconn = (FileConnection) Connector.open(filepath,
					Connector.READ_WRITE);
			if (!fileconn.exists()) {
				fileconn.create();
			}

			Document doc = new Document();
			Element root = doc.createElement("", "TelliT");
			Element server = doc.createElement("", "server");

			Element ipelem = doc.createElement("", "ip");
			ipelem.addChild(Node.TEXT, ip);

			Element portelem = doc.createElement("", "port");
			portelem.addChild(Node.TEXT, port);

			server.addChild(Node.ELEMENT, ipelem);
			server.addChild(Node.ELEMENT, portelem);

			root.addChild(Node.ELEMENT, server);
			doc.addChild(Node.ELEMENT, root);

			DataOutputStream outstream;

			outstream = fileconn.openDataOutputStream();
			KXmlSerializer serializer = new KXmlSerializer();
			serializer.setOutput(outstream, "UTF-8");
			doc.write(serializer);
			fileconn.close();

		} catch (Exception e) {
			Dialog.alert("Data could not be saved: " + e.getMessage());
		}

}

}

Open in new window

0
Comment
Question by:KristjanLaane
1 Comment
 

Accepted Solution

by:
KristjanLaane earned 0 total points
ID: 33764844
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 81
Java. Convert method from recursion based to iteration based ( loop based ) 6 77
servlet example issue 6 32
expectj telnet failing 5 26
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now