在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的方法,还有别的么?