Click here to Skip to main content
15,917,991 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import java.io.*;
public class MyMidlet extends MIDlet implements CommandListener
{
    Command write;
    Display disp;
    Form frm;
    public MyMidlet()
    {
        disp=Display.getDisplay(this);
        frm=new Form("Write File..");
        write=new Command("Write", Command.OK, 0);
        frm.addCommand(write);
        frm.setCommandListener(this);
       
    }
    public void startApp() 
    {
        disp.setCurrent(frm);
    }
    public void pauseApp() {
    }
    public void destroyApp(boolean unconditional) {
    }
    
    public void commandAction(Command c, Displayable d)
    {
        if(c==write)
        {
            new Thread(new Runnable() {
                public void run()
                {
                     try
					{
						OutputConnection con = (OutputConnection) Connector.open("file:///root1/myfile.txt; appent=false",Connector.WRITE);
						PrintStream p=new PrintStream(con.openDataOutputStream());
						p.println("All is well..");
						p.close();	
						con.close();	
						
						Alert alt=new Alert("Completed","Data Written", null, AlertType.ALARM);
						alt.setTimeout(Alert.FOREVER);
						disp.setCurrent(alt);
					}
					catch (IOException ex)
					{
						Alert alt=new Alert("Error",ex.toString(), null, AlertType.ALARM);
						alt.setTimeout(Alert.FOREVER);
						disp.setCurrent(alt);
						//ex.printStackTrace();
					}
                }
            }).start();
        }
    }
}


The above code is writing a file onto the system but I get java.io.IOEXCEPTION when I execute it on mobile and wireless toolkit 2.5.2.
Posted
Updated 27-Mar-11 4:31am
v2
Comments
Dalek Dave 27-Mar-11 10:32am    
Edited for Code Block and Grammar.

1 solution

Your problem is (obviously) in the first two lines in the try block. Both Connector.open() and OutputConnection.openDataOutputStream() can throw java.io.IOException. The quick way to see which is to put an Alert between them. If it displays, the problem is in the second line. If not, it's the first line.

:doh: Looking again at your code, are you sure it's not the spelling of appent=false"? Are such modifiers allowed inside the URL for Connector.open? Is the space allowed?

Cheers,
Peter
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900