在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的方法,还有别的么?
解决方案 »
- 运行时报分号错误,不懂。。。求解释!!!
- WebView loadurl做的浏览器,却打开不了网页
- 关于imageView.setImageResource导致图像失真的问题
- 如何在ItemizedOverlay中实现startactivity跳转
- 关于eclipse下开发android,弹出成员函数是暴卡的问题,原来是ADT的问题!
- 联网时获取响应码时卡住该怎么办
- android中数据库内容写入到外部txt文件
- http上传问题
- 请问关于添加 textview 点击事件报错的问题
- Android工程中bin目录下为什么.apk文件是空的???
- 如何做景区地图
- 手机间的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;
}我们先前就是这样写的.