java如何将读取串口的数据写入TXT保存?
1个回答
展开全部
你好:这个的话,你可以参考下,我使用map做的
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Map map = new HashMap();
map.put("k1","v1");
map.put("k2","v2");
map.put("k3","v3");
try {
String line = System.getProperty("line.separator");
StringBuffer str = new StringBuffer();
FileWriter fw = new FileWriter("D:\\1.txt", true);
Set set = map.entrySet();
Iterator iter = set.iterator();
while(iter.hasNext()){
Map.Entry entry = (Map.Entry)iter.next();
str.append(entry.getKey()+" : "+entry.getValue()).append(line);
}
fw.write(str.toString());
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询