java将字符串写入到文件中
来源:互联网 发布:et200proprofinet网络 编辑:程序博客网 时间:2024/05/02 11:59
将页面上获取的字符串内容写入到指定目录下新的csv文件中,并在行首添加id
String sourceData = request.getParameter("generateData");String fileName = request.getParameter("fileName");fileName=fileName.replaceAll(".csv", "_add_id.csv");BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(sourceData.getBytes(Charset.forName("utf8"))), Charset.forName("utf8")));String line;File savePath = new File("F:/generateId");// 判断上传文件的保存目录是否存在 if (!savePath.exists() && !savePath.isDirectory()) { System.out.println(savePath + "目录不存在,需要创建"); // 创建目录 savePath.mkdir(); }BufferedWriter bw = new BufferedWriter(new FileWriter(savePath + "/" + fileName));// FileWriter(csv, true) 当参数为true的时候写入的数据会叠加不会覆盖Set set = new HashSet();while (set.size() < 100000) {int val = (int) (Math.random() * 100000);set.add(val);}Iterator iterator = set.iterator();while ( (line = br.readLine()) != null && iterator.hasNext() ) {Integer id=(Integer) iterator.next(); bw.write(id+","+line); bw.newLine(); }bw.close();
0 0
- java将字符串写入到文件中
- java将字符串写入到txt文件中
- 将字符串写入到txt文件中
- java 将对象写入到文件中
- java的io操作(将字符串写入到txt文件中)
- java的io操作(将字符串写入到txt文件中)
- VC将字符串写入到txt文件中
- 将字符串json写入到服务器文件中
- java中,将一串字符串写入到本地文档中
- Java将字符串写入文件与将文件内容读取到字符串
- java写入字符串到文件
- Java学习笔记1:将字符串写入txt文件中
- Java 将sytem.out 数据写入到文件中
- Java 将内容写入到某个文件中
- java将数据写入到csv文件中
- 字符串写入文件 C++ 读文件 将文件内容读入到字符串string中
- java 将字符串写入到文本文件
- java将字符串写入到文本里
- Android Tombstone/Crash的log分析和定位
- 深入理解javascript原型和闭包(15)——闭包
- Mysql 查看连接数,状态
- easyui中datagrid分页问题
- 打印沙漏
- java将字符串写入到文件中
- Mybatis接口编程方式实现增删改查
- python删除pandas DataFrame的某一/几列
- 谈谈集成显卡双2K/4K输出的那点事情
- 设计模式----面向对象的六大原则
- 仿支付宝咻一咻效果
- 常见证书格式转换
- 文本编辑器
- 音视频的帧