2

I am facing the problem with openfileinput class. First thing is , I am saving my username and password in the file.On sucessful login, I will be saving and moving to internal home screen.The problem is when I logout or close the application, and reopen the application I am able to read the data but when I convert it to String I get Out put as AAAAAA(each as 4 bytes). On succesful login on moving to Home screen , I am able to read it properly.I get this output before login.

This is something like , saving username and password in internal memory of android.

Regards:

Jayanth Gande

user320276
  • 59
  • 1
  • 7
  • String data = ""; try { data += userName.getText().toString() + " "; data += password.getText().toString() + " "; data += cal.get(Calendar.DATE) + " "; data += cal.get(Calendar.MONTH) + " "; data += cal.get(Calendar.YEAR) + " "; FileOutputStream fos = openFileOutput(TDCommons.FILENAME, MODE_PRIVATE); Log.i("Data writing into file", data); fos.write(data.getBytes()); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } – user320276 Jun 15 '10 at 04:57
  • byte[] filedata; FileInputStream fis = openFileInput(TDCommons.FILENAME); filedata = new byte[fis.available()]; StringTokenizer stk = new StringTokenizer(new String(filedata), " "); if (fis.available() != 0) { if (stk.hasMoreTokens()) { username = stk.nextToken(); } if (stk.hasMoreTokens()) { pwd = stk.nextToken(); } if (stk.hasMoreTokens()) { date = stk.nextToken(); } if (stk.hasMoreTokens()) { month = stk.nextToken(); } if (stk.hasMoreTokens()) { year = stk.nextToken(); } fis.close(); – user320276 Jun 15 '10 at 05:00

0 Answers0