我有一个布局,我有一个编辑文本字段,我输入我的数据。 我有2个按钮。保存和绘图。
当我按保存时,我想从edittext字段保存数据(xls格式),并在sd卡中保存当前日期。
当我按下情节时,我想绘制它们。
保存数据:
case R.id.savebtn:
savefunc();
break;
...
public void savefunc(){
//saving
File sdCard = Environment.getExternalStorageDirectory();
File directory = new File (sdCard, "MyFiles");
directory.mkdirs();
File file = new File(directory, filename);
try {
FileOutputStream fOut = new FileOutputStream(file);
DataOutputStream os = new DataOutputStream(fOut);
os.writeUTF(thedata);
os.writeUTF(mydate);
os.close();
} catch (FileNotFoundException e) {
// handle exception
} catch (IOException e) {
// handle exception
}
}
阅读:
public void readfunc(){
File sdCard = Environment.getExternalStorageDirectory();
File directory = new File (sdCard, "MyFiles");
File file = new File(directory, filename);
try{
FileInputStream fIn = new FileInputStream(file);
DataInputStream is = new DataInputStream(fIn);
String name = is.readUTF();
String content = is.readUTF();
is.close();
} catch (FileNotFoundException e) {
// handle exception
} catch (IOException e) {
// handle exception
}
}
和:
case R.id.savebtn:
savefunc();
break;
case R.id.graphicsbtn:
readfunc();
...
但是xls文件问我格式,我选择UTF8并且它是空的。
如果我离开它会显示中文字符。
我不确定代码的“阅读”部分。