我写了一个Android应用程序,只是将文本和日期输出到SD卡上的文件。
public class MyWastedTimeActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText ujET=(EditText)findViewById(R.id.input);
Button gomb=(Button)findViewById(R.id.button1);
final String ujString=ujET.getText().toString();
gomb.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
commitToFile(ujString);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
private void commitToFile(String mit) throws IOException {
String aktIdo = DateFormat.getDateInstance().format(new Date());
String kiIr =aktIdo+" "+mit+"\n";
FileOutputStream fos = null;
ObjectOutputStream out = null;
File root = Environment.getExternalStorageDirectory();
fos = new FileOutputStream( root + "/" +"idom.txt" ,true);
out = new ObjectOutputStream( fos );
out.writeObject( kiIr );
out.close();
}
}
问题是,当我在电脑上打开“idom.txt”文件时,它给了我:Ԁt䴎ㄠⰸ갊琅琅愠㠱㈱ਠ㈱ਠ当它真的不是我写的......有什么建议吗?