java File读写
来源:互联网 发布:d3.js官网 编辑:程序博客网 时间:2024/06/16 17:05
import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;/** * @author pc2013 * */public class File001 {/** * @param args */public static void main(String[] args) {BufferedWriter bw = null;BufferedReader br = null;try {File file = new File("d:" + File.separator + "test.txt");if (file.exists()) {System.out.println("file exist");if (file.canExecute()) {System.out.println("this is a executive file");}if (file.canRead()) {System.out.println("this file can be read");}if (file.canWrite()) {System.out.println("this file can be write");}} else {System.out.println("file not exist");boolean flag = file.createNewFile();if (flag == true) {System.out.println("the file test.txt created successfully");} else {System.out.println("file created failure");}}br = new BufferedReader(new FileReader(file));StringBuffer sb = new StringBuffer();String str = null;if (file.length() == 0) {System.out.println("the file is empty" + file.length());} else {System.out.println("the file takes up " + file.length()+ " bytes");while ((str = br.readLine()) != null) {sb.append(str);}}bw = new BufferedWriter(new FileWriter(file));bw.write(sb.toString());for(int i = 0; i < 30; ++i) {bw.write("this is the test date");}System.out.println("write complete, the file takes up " + file.length() + " bytes");} catch (Exception e) {e.printStackTrace();} finally {if (br != null) {try {br.close();} catch (IOException e) {e.printStackTrace();}}if (bw != null) {try {bw.close();} catch (IOException e) {e.printStackTrace();}}}}}
0 0
- java File读写大全
- java File读写
- java File 文件读写
- java File的读写
- java读写file
- Java中的File类 读写复制文件
- java中的File文件读写操作
- java中的File文件读写操作
- java File/IO读写文件 字节流
- File 读写
- file读写
- 【跟着imooc重学java】Java File IO读写操作
- 【Java】File类文件管理及IO读写、复制操作
- Java文件读写操作(file I/O)
- FILE*读写文件
- file文件的读写
- File类读写
- File的读写方法
- 60-爱因斯坦的阶梯问题
- OpenGL学习二十一:纹理坐标
- gdb调试之--read by other session 等待事件的重现
- linux删除重复行
- 《机器学习实战》k-近邻算法概述-程序清单详解kNN.py(未完待续)
- java File读写
- MediCool天使投资计划
- Apriori算法详解
- HDU 1010 Tempter of the Bone
- dbms_profiler 调整PL/SQL的性能
- 《高效程序员的45个习惯——敏捷开发修炼之道》读书总结
- 银行应对互联网金融
- ccsm ubuntu 特效软件使用记录
- SET的一些知识点