小弟初学不久,目前的手机程序已经可以进行数据的接收并且存入sD卡,(前端是一个单片机控制蓝牙串口模块发送数据)。可是经过仔细观察,发现程序工作很不稳定,经常会出现大的波动,丢掉成片的数据。实在不清楚是什么原因,程序修改都没修改过,为什么会有如此大的起伏?以下是读写部分的代码:
byte b[] = new byte[1024] ;
try {
inStream.read(b,0,1024);
System.out.println(new String(b));
} catch (Exception e) {
System.out.println("写入数据异常");
}
//以下 的是将数据流中的数据写入根目录下的data文件中
try{
File f = new File(SDPATH + "data.txt");
out = new FileOutputStream(f);
//while((inStream.read(b)) != -1){
while(D){
out.write(b,0,1024);
System.out.println("正在存储数据");
out.flush();
inStream.read(b,0,1024);
}
byte b[] = new byte[1024] ;
try {
inStream.read(b,0,1024);
System.out.println(new String(b));
} catch (Exception e) {
System.out.println("写入数据异常");
}
//以下 的是将数据流中的数据写入根目录下的data文件中
try{
File f = new File(SDPATH + "data.txt");
out = new FileOutputStream(f);
//while((inStream.read(b)) != -1){
while(D){
out.write(b,0,1024);
System.out.println("正在存储数据");
out.flush();
inStream.read(b,0,1024);
}
解决方案 »
- 哥哥们,我已经被这个sendMultipartTextMessage弄崩溃了,行行好给看看吧
- 加了try catch报错
- 开始投入Android 的阵营。
- 求代码:android listview checkbox 从数据库里读取数据后怎么设置相应的checkbox为选中状态
- 谷歌地图可以不可像百度地图那样通过一个链接上传经纬度来获取地图截图
- 内存拷贝的性能问题
- killbackgroundprocesses无效
- android前景如何
- 哥哥姐姐们求解惑。。。。
- android studio 编译报错
- 耐力测试的时候,mmap映射失败,看log是地址一直在增加,求为什么?
- android2.3 如何进行串口开发 求大神
try {
inStream.read(b,0,1024);
System.out.println(new String(b));
} catch (Exception e) {
System.out.println("写入数据异常");
}
//以下 的是将数据流中的数据写入根目录下的data文件中
try{
File f = new File(SDPATH + "data.txt");
out = new FileOutputStream(f);
while((inStream.read(b)) != -1){
out.write(b,0,1024);
System.out.println("正在存储数据");
out.flush();
inStream.read(b,0,1024);
}
out.flush();