为什么我的文件不能写入文本插入?

问题描述:

我正在做一个黑莓的API,但现在我有一个问题,该文件不保存文本插入,例如,当我在应用程序运行时写:你好,我猜这个“你好”是保存在EditField pt_nombre,为什么我的文件不能写入文本插入?

name = new LabelField("Nombre"); 
pt_nombre = new FixedWidthEditField(); 



String a = pt_nombre.getText(); 
String nom = name.getText(); 

String fullPath = "file:///SDCard/xxx.txt"; 

try { 
    FileConnection fconn = (FileConnection) Connector.open(fullPath, Connector.READ_WRITE); 
    if (fconn.exists()) { 
     fconn.delete(); 
    } 

    fconn.create(); 
    OutputStream os = fconn.openOutputStream(); 

    os.write(nombre.getBytes()); 
    os.write("\r\n".getBytes()); 
    os.write(a.getBytes()); 

    fconn.close(); 
} catch (IOException e) { 
    System.out.println("Oh noes!!1! " + e.toString()); 
} 

当我检查xxx.txt时,只写了Label,Nombre:但EditField中的文字不是!请帮助

你确定这段代码甚至编译?我不知道在哪里声明了nombre(甚至在名称和pt_nombre被“声明”的范围内);也没有任何地方可以为pt_nombre设置一个值,所以我不知道你在文件中看到的是什么。

你应该检查FixedWidthEditField getText函数。 它会返回用户输入的文字