質問

私のBlackBerryのアプリケーションでの読み取り/書き込みテキストファイルのサンプルコードをお願いします。

正しい解決策はありません

他のヒント

文字列の読み取りのための私のコードスニペット/ファイルを書き込む:

private String readTextFile(String fName) {
  String result = null;
  FileConnection fconn = null;
  DataInputStream is = null;
  try {
   fconn = (FileConnection) Connector.open(fName, Connector.READ_WRITE);
   is = fconn.openDataInputStream();
   byte[] data = IOUtilities.streamToBytes(is);
   result = new String(data);
  } catch (IOException e) {
   System.out.println(e.getMessage());
  } finally {
   try {
    if (null != is)

     is.close();
    if (null != fconn)
     fconn.close();
   } catch (IOException e) {
    System.out.println(e.getMessage());
   }
  }
  return result;
 }
<時間>
private void writeTextFile(String fName, String text) {
  DataOutputStream os = null;
  FileConnection fconn = null;
  try {
   fconn = (FileConnection) Connector.open(fName, Connector.READ_WRITE);
   if (!fconn.exists())
    fconn.create();

   os = fconn.openDataOutputStream();
   os.write(text.getBytes());
  } catch (IOException e) {
   System.out.println(e.getMessage());
  } finally {
   try {
    if (null != os)
     os.close();
    if (null != fconn)
     fconn.close();
   } catch (IOException e) {
    System.out.println(e.getMessage());
   }
  }
 }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top