2011-10-06 128 views
0

我正在做一個黑莓的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中的文字不是!請幫助

回答

0

你確定這段代碼甚至編譯?我不知道在哪裏聲明瞭nombre(甚至在名稱和pt_nombre被「聲明」的範圍內);也沒有任何地方可以爲pt_nombre設置一個值,所以我不知道你在文件中看到的是什麼。

0

你應該檢查FixedWidthEditField getText函數。 它會返回用戶輸入的文字