在手机中执行项目时得到java.io.IOEXCEPTION [英] I get java.io.IOEXCEPTION when project is execute in mobile phone

查看:147
本文介绍了在手机中执行项目时得到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.

推荐答案

(显然)在try块的前两行中. Connector.open()OutputConnection.openDataOutputStream()都可以抛出java.io.IOException.快速查看方法是在它们之间放置一个警报.如果显示,则问题出在第二行.如果不是,则为第一行.

:doh:再次查看您的代码,确定不是appent=false"的拼写吗?在Connector.open的URL内是否允许使用此类修饰符?可以使用空间吗?

干杯,
彼得
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


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆