在Activity中有个数组a[] = {1, 0, 0, 1, 0}; 目标是将这个数组a储存到一个txt文本中
刚接触安卓只掌握了如下Properties+FileOutputStream的方法:
private boolean save(String fileNmae)
{
Properties properties = new Properties();
将数据打包成Properties
for(int num = 0; num<5; num++){
properties.put(""+num, String.valueOf(a[num]));
}
try
{
FileOutputStream stream = this.openFileOutput(fileNmae, Context.BIND_ABOVE_CLIENT);
将打包好的数据写入文件中
properties.store(stream, "");
}
catch (FileNotFoundException e)
{
return false;
}
catch (IOException e)
{
return false;
} return true;
}
这样之后得到txt里的内容都是键值对的形式,如0=1 1=0 2=0 3=1 4=0
而目标是txt里的内容是单纯的10010,而不是键值对。
我试了下普通java程序中文本的输出方式如下:
private static boolean save(String fileName) {
try {
File file = new File(fileName);
FileWriter filewriter = new FileWriter(file, true);
for(int num = 0; num<5;num++){
filewriter.write(a[num]);
}
filewriter.close();
} catch (IOException e) {
return false;
} catch (Exception ex) {
return false;
}
return true;
}
这在安卓程序里好像不会生成输出文件。希望说清楚了,重点就是安卓里文件写出除了Properties+FileOutputStream的方法,还有别的么?
刚接触安卓只掌握了如下Properties+FileOutputStream的方法:
private boolean save(String fileNmae)
{
Properties properties = new Properties();
将数据打包成Properties
for(int num = 0; num<5; num++){
properties.put(""+num, String.valueOf(a[num]));
}
try
{
FileOutputStream stream = this.openFileOutput(fileNmae, Context.BIND_ABOVE_CLIENT);
将打包好的数据写入文件中
properties.store(stream, "");
}
catch (FileNotFoundException e)
{
return false;
}
catch (IOException e)
{
return false;
} return true;
}
这样之后得到txt里的内容都是键值对的形式,如0=1 1=0 2=0 3=1 4=0
而目标是txt里的内容是单纯的10010,而不是键值对。
我试了下普通java程序中文本的输出方式如下:
private static boolean save(String fileName) {
try {
File file = new File(fileName);
FileWriter filewriter = new FileWriter(file, true);
for(int num = 0; num<5;num++){
filewriter.write(a[num]);
}
filewriter.close();
} catch (IOException e) {
return false;
} catch (Exception ex) {
return false;
}
return true;
}
这在安卓程序里好像不会生成输出文件。希望说清楚了,重点就是安卓里文件写出除了Properties+FileOutputStream的方法,还有别的么?
解决方案 »
- 大家能不能推荐几本比较好的android的书,顺便说一下怎么学习android
- new ImageSwitcher.LayoutParams(-1, -1)什么意思?为什么要设置为-1
- 如何彻底屏蔽“输入法”。
- 用SimpleAdapter创建ListView
- 继承ArrayAdapter,重写getView时,convertView setTag与holder里addTextChangedListener同时存在出错
- 安卓手机2.1x系统用第三方播放器看视频会出现卡顿,花屏现象,为什么?
- 如何获取已经下载过的APK
- 有人用过百度的社会化分享组件么?来看看
- 请教java里gson解析问题
- android如何通过usb下载pc上的数据
- 如何做景区地图
- 手机间的socket通信。出现莫名其妙的问题
try {
File file = new File(fileName);
FileWriter filewriter = new FileWriter(file, true);
for(int num = 0; num<5;num++){
filewriter.write(a[num]);
}
filewriter.close();
} catch (IOException e) {
return false;
} catch (Exception ex) {
return false;
}
return true;
}我们先前就是这样写的.