j2me读写文件问题

下面是我写文件写入代码,为什么不能创建文件呢,单步调式到红色标记是就过不去了
package file;

import java.io.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import javax.microedition.io.Connector;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.io.file.FileConnection;


public class Filetest extends MIDlet implements CommandListener,Runnable {
private Display display;
private Command exit = new Command("Exit",Command.EXIT,1);
private Command start = new Command("Start",Command.SCREEN,1);
private Form form;
public Filetest() {
// TODO Auto-generated constructor stub
display = Display.getDisplay(this);
form = new Form("fileTest");
form.addCommand(exit);
form.addCommand(start);
form.setCommandListener(this);
}

protected void destroyApp(boolean arg0)  {
// TODO Auto-generated method stub

}

protected void pauseApp() {
// TODO Auto-generated method stub

}

protected void startApp()  {
// TODO Auto-generated method stub
display.setCurrent(form);
}
public void commandAction(Command c,Displayable d){
if(c == exit){
destroyApp(false);
notifyDestroyed();
}
if(c == start){
new Thread(this).start();
}
}
public void run() { 
        String path = "file:///root1/test.txt";// 模拟器上的路径 
        byte[] b = "hello world".getBytes();// 这里先写入hello world 

        try { 
            // path为文件路径及文件名 
             FileConnection fc = (FileConnection) Connector.open(path,Connector.READ_WRITE); 
            if (!fc.exists())// 若文件不存在,创建文件 
                fc.create(); 
            OutputStream os = fc.openOutputStream();// 打开输出流 
            os.write(b);// b为byte[] 要写入的文件数据 
            os.close(); 
            fc.close(); 
        } catch (IOException e) { 
            // TODO 自动生成 catch 块 
            e.printStackTrace(); 
        } 
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值