本文介绍了在手机中执行项目时得到java.io.IOEXCEPTION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();
        }
    }
}



上面的代码正在将文件写到系统上,但是当我在移动和无线工具包2.5.2中执行该文件时,我得到java.io.IOEXCEPTION.



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.

推荐答案


这篇关于在手机中执行项目时得到java.io.IOEXCEPTION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 18:18