import java.io.*;

public class Study {
public static void main(String[] args) {
try {
String strPath = "d:\\myTest\\abc.txt";
File txtFile = new File(strPath);
if( !txtFile.exists() ){
System.out.println("No found text file.");
System.out.println(txtFile.getPath());
System.out.println(txtFile.getName());
System.out.println(txtFile.getParentFile().getPath());
boolean bMakeDir = txtFile.getParentFile().mkdir();
System.out.println(bMakeDir);
System.out.println(txtFile.createNewFile());
}
else{
System.out.println("Yes, the text file already existing.");
} String strDir = "D:\\myTest";
File dir = new File(strDir);
System.out.println(dir.isFile());
System.out.println(dir.isDirectory()); FileWriter fw = new FileWriter(txtFile);
fw.write("abcdefg");
fw.close(); String txt;
StringBuilder text = new StringBuilder();
BufferedReader br = new BufferedReader(new FileReader(txtFile));
while((txt = br.readLine()) != null){
text.append(txt);
}
System.out.println(text); txtFile.deleteOnExit();
}
catch( IOException ex ){
ex.printStackTrace();
}
}
}

Java文件读写的更多相关文章

  1. java 文件读写的有用工具

    java 文件读写的有用工具 package org.rui.io.util; import java.io.BufferedReader; import java.io.File; import j ...

  2. java文件读写的两种方式

    今天搞了下java文件的读写,自己也总结了一下,但是不全,只有两种方式,先直接看代码: public static void main(String[] args) throws IOExceptio ...

  3. java文件读写操作

    Java IO系统里读写文件使用Reader和Writer两个抽象类,Reader中read()和close()方法都是抽象方法.Writer中 write(),flush()和close()方法为抽 ...

  4. java文件读写操作类

    借鉴了项目以前的文件写入功能,实现了对文件读写操作的封装 仅仅需要在读写方法传入路径即可(可以是绝对或相对路径) 以后使用时,可以在此基础上改进,比如: 写操作: 1,对java GUI中文本框中的内 ...

  5. Java 文件读写操作

    1[1]按字节读写,一次只读取一个字节,效率比较低 package bk1; import java.io.File; import java.io.FileInputStream; import j ...

  6. Java文件读写分析

    本文内容:IO流操作文件的细节分析:分析各种操作文件的方式. 读写一个文件 从一个示例开始分析,如何操作文件: /** * 向一个文件中写入数据 * @throws IOException */ pr ...

  7. java文件读写操作指定编码格式

    读文件: BufferedReader 从字符输入流中读取文本,缓冲各个字符,从而提供字符.数组和行的高效读取. 可以指定缓冲区的大小,或者可使用默认的大小.大多数情况下,默认值就足够大了. 通常,R ...

  8. java文件读写工具类

    依赖jar:commons-io.jar 1.写文件 // by FileUtilsList<String> lines = FileUtils.readLines(file, " ...

  9. java 文件读写--转载

    读文件 http://www.baeldung.com/java-read-file Java – Read from File 1. Overview In this tutorial we’ll ...

  10. java 文件读写工具 FileUtil

    代码如下: package com.wiscom.utils; import java.io.BufferedReader; import java.io.File; import java.io.F ...

随机推荐

  1. mySQL CRUD操作(数据库的增删改查)

    一.数据库操作 1.创建数据库 create database 数据库名称 2.删除数据库 drop database 数据库名称   二.表操作 1.创建表 create table 表名 (    ...

  2. MAVEN ERROR : Dynamic Web Module 3.0 requires Java 1.6 or newer

    问题: 在eclipse中,通过Maven->Update Project更新项目后,出现Dynamic Web Module 3.0 requires Java 1.6 or newer错误提 ...

  3. VIM键盘快捷键映射

    http://www.jianshu.com/p/216811be226b

  4. 长方形—C++

    编程之美一道简单的热身题,活生生的组合数学例子啊. 题意如下: 在 N 条水平线与 M 条竖直线构成的网格中,放 K 枚石子,每个石子都只能放在网格的交叉点上.问在最优的摆放方式下,最多能找到多少四边 ...

  5. .net利用本地播放器播放视频文件代码

    前台点击按钮,执行js事件,跳转到后台代码: function funShowVideo(index) {            var iTop = (window.screen.availHeig ...

  6. 转载:LBP代码详细注释

    %LBP returns the local binary pattern image or LBP histogram of an image.% J = LBP(I,R,N,MAPPING,MOD ...

  7. 用java将excel表格中的内容修改后写入到另一个excel中

    package nn; import java.io.File; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl. ...

  8. Spring MVC数组绑定

    需求:商品批量删除,用户在页面选择多个商品,批量删除. 关键:将页面选择(多选)的商品id,传到controller方法的形参,方法形参使用数组接收页面请求的多个商品id // 批量删除 商品信息 @ ...

  9. spring mvc 重定向传参

    参考链接如下: http://bbs.csdn.net/topics/391034118?page=1 自己的示例程序: 详细页面提交一个修改动作,修改完成后跳转到检索页面,把检索条件重新赋值给检索页 ...

  10. Eclipse中web-inf和meta-inf文件夹的信息

    http://www.cnblogs.com/chinafine/archive/2010/06/13/1757514.html WEB-INF     /WEB-INF/web.xml        ...