一种对文件读取和写入数据的方法
来源:互联网 发布:c语言集成开发环境功能 编辑:程序博客网 时间:2024/05/17 19:14
10.读取固定路径下的文件的一种方法:private static String getJson() throws Exception {FileInputStream inputStream = new FileInputStream("c://video.json");BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));String str = "";StringBuffer json = new StringBuffer();while ((str = bufferedReader.readLine()) != null) {json.append(str);}bufferedReader.close();inputStream.close();return json.toString();}11.将数据写入一个已知的文件中:int year = Calendar.getInstance().get(Calendar.YEAR);int month = Calendar.getInstance().get(Calendar.MONTH) + 1;int day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);Date date=new Date();SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyyMMddHHmmss");String currenttime=simpleDateFormat.format(date);String jsondataPath=year+"/"+month+"/"+day;//String jsondataPath = "D://" + year + "//" + month + "//" + day;String filename = currenttime + ".json";先创建文件夹,然后开始读写操作, File file = new File(jsondataPath);if (!file.exists()) {file.mkdirs();}File file2 = new File(jsondataPath, filename);if (!file2.exists()) {try {file2.createNewFile();} catch (Exception e) {e.printStackTrace();}}FileOutputStream writerStream = new FileOutputStream(fileEntity);BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(writerStream, "UTF-8"));writer.write(jsondata);writer.close();
阅读全文
0 0
- 一种对文件读取和写入数据的方法
- unity中四种读取txt文件的方法和一种写入txt方法
- qt数据写入文件和读取文件里的数据
- Android应用程序对SD卡数据的写入和读取
- php操作XML,读取数据和写入数据的方法
- php操作XML,读取数据和写入数据的方法
- C++对txt文件的读取和写入
- VC++中对文件的写入和读取
- VC++中对文件的写入和读取
- VC++中对文件的写入和读取
- c++对txt文件的读取和写入
- Dom4J对XML文件的读取和写入
- C++学习笔记:对文件流的写入和读取
- DOM对象对xml文件的读取和写入
- jsp文件操作:读取和写入文件的方法
- IO流对文件读取和写入
- 文件的读取和写入
- ******************* 文件的写入和读取 *******************
- SpringAOP拦截Controller,Service实现日志管理(自定义注解的方式)
- spring boot 跨域配置
- C&C++编译环境构建
- pc端页面body需设置min-width
- web性能测试基本性能指标
- 一种对文件读取和写入数据的方法
- 深度学习论文
- 目标跟踪算法概述
- java导出Excel之多个sheet
- 修改Android studio新建activity默认根布局
- liunx基础背景与操作指令
- 51nod 1305 Pairwise Sum and Divide
- Kirinriki HDU
- 一文读懂大数据:Hadoop,大数据技术及相关应用