本人小白一枚,最近写了一个文件读写的demo,但在\data\data\包名\ 下生成的文件不是txt格式,却是这么个东东,所以想让各位大神看看问题在哪里
代码:public class MainActivity extends Activity {
private EditText mfilename;
private EditText mfilecontent;
private Button msave;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mfilename = (EditText) findViewById(R.id.filename);
mfilecontent= (EditText) findViewById(R.id.filecontent);
msave = (Button) findViewById(R.id.save);
msave.setOnClickListener(new saveClickListener());
}
private class saveClickListener implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String filename = mfilename.getContext().toString();
String filecontent = mfilecontent.getContext().toString();
FileService service = new FileService(getApplicationContext());
try {
service.save(filename,filecontent);
Toast.makeText(getApplicationContext(), R.string.success, 1).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(getApplicationContext(), R.string.fail, 1).show();
}
}
}
}
import android.content.Context;
public class FileService {
private Context context;
public FileService(Context context) {
super();
this.context = context;
}
public void save(String filename, String filecontent) throws Exception {
// TODO Auto-generated method stub
FileOutputStream output = context.openFileOutput(filename, Context.MODE_PRIVATE);
output.write(filecontent.getBytes());
output.close();
}
}