file-connection

Reading Content from File in J2ME

瘦欲@ 提交于 2019-12-10 19:49:13
问题 I am trying to read the content of a file but it seems not to work. I surfed the net and found different implementations as shown(read(), read2(), readLine()) but each time a run the codes they all give a NullPointer exception. Please what can I do to rectify this problem. private String folder; static String filename; //IMPLEMENTATION 1 private void readFile(String f) { try { InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream(f)); String line = null; while ((line

how to read/write text file in j2me

泪湿孤枕 提交于 2019-11-29 11:09:17
i want to know how to read and write text to a .txt file in j2me help me thanks... public String readFile(String path) { InputStream is = null; FileConnection fc = null; String str = ""; try { fc = (FileConnection)Connector.open(path, Connector.READ_WRITE); if(fc.exists()) { int size = (int)fc.fileSize(); is= fc.openInputStream(); byte bytes[] = new byte[size]; is.read(bytes, 0, size); str = new String(bytes, 0, size); } } catch (IOException ioe) { Alert error = new Alert("Error", ioe.getMessage(), null, AlertType.INFO); error.setTimeout(1212313123); Display.getDisplay(main).setCurrent(error);

how to read/write text file in j2me

孤街醉人 提交于 2019-11-28 04:43:26
问题 i want to know how to read and write text to a .txt file in j2me help me thanks... 回答1: public String readFile(String path) { InputStream is = null; FileConnection fc = null; String str = ""; try { fc = (FileConnection)Connector.open(path, Connector.READ_WRITE); if(fc.exists()) { int size = (int)fc.fileSize(); is= fc.openInputStream(); byte bytes[] = new byte[size]; is.read(bytes, 0, size); str = new String(bytes, 0, size); } } catch (IOException ioe) { Alert error = new Alert("Error", ioe