我需要使用文件输出流从编辑文本保存到文件或列表,但是每次我用编辑文本中写入的名称保存时,都会创建一个新文件,我怎样才能只制作一个文件,每次输入数据时在编辑文本中它只更新同一个文件。
另外,如何将计数器添加到文件中
Button save;
EditText Username, ID;
String FILENAME, JOUR;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.internal);
save = (Button) findViewById(R.id.button1);
save.setOnClickListener(this);
Username = (EditText) findViewById(R.id.editText1);
ID = (EditText) findViewById(R.id.editText2);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
FILENAME = Username.getText().toString();
if (FILENAME.contentEquals("")){
finish();
}
JOUR = ID.getText().toString();
Username.setText("");
ID.setText("");
try {
FileOutputStream fos = openFileOutput(FILENAME , Context.MODE_PRIVATE);
fos.write(JOUR.getBytes());
// fos.write(FILENAME.getBytes());
fos.close();
Toast.makeText(
InternalStore.this,
FILENAME + " saved",
Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}