Java文件读写
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文件读写的更多相关文章
- java 文件读写的有用工具
java 文件读写的有用工具 package org.rui.io.util; import java.io.BufferedReader; import java.io.File; import j ...
- java文件读写的两种方式
今天搞了下java文件的读写,自己也总结了一下,但是不全,只有两种方式,先直接看代码: public static void main(String[] args) throws IOExceptio ...
- java文件读写操作
Java IO系统里读写文件使用Reader和Writer两个抽象类,Reader中read()和close()方法都是抽象方法.Writer中 write(),flush()和close()方法为抽 ...
- java文件读写操作类
借鉴了项目以前的文件写入功能,实现了对文件读写操作的封装 仅仅需要在读写方法传入路径即可(可以是绝对或相对路径) 以后使用时,可以在此基础上改进,比如: 写操作: 1,对java GUI中文本框中的内 ...
- Java 文件读写操作
1[1]按字节读写,一次只读取一个字节,效率比较低 package bk1; import java.io.File; import java.io.FileInputStream; import j ...
- Java文件读写分析
本文内容:IO流操作文件的细节分析:分析各种操作文件的方式. 读写一个文件 从一个示例开始分析,如何操作文件: /** * 向一个文件中写入数据 * @throws IOException */ pr ...
- java文件读写操作指定编码格式
读文件: BufferedReader 从字符输入流中读取文本,缓冲各个字符,从而提供字符.数组和行的高效读取. 可以指定缓冲区的大小,或者可使用默认的大小.大多数情况下,默认值就足够大了. 通常,R ...
- java文件读写工具类
依赖jar:commons-io.jar 1.写文件 // by FileUtilsList<String> lines = FileUtils.readLines(file, " ...
- java 文件读写--转载
读文件 http://www.baeldung.com/java-read-file Java – Read from File 1. Overview In this tutorial we’ll ...
- java 文件读写工具 FileUtil
代码如下: package com.wiscom.utils; import java.io.BufferedReader; import java.io.File; import java.io.F ...
随机推荐
- 消格子时一个很深的bug的修复纪录
环境: cocos2d-x 2.2.2 jsb 条件:当快速在格子中来回拖拽选取时,会一直在计算指尖和格子的真实区域是否碰撞, 报错:touchMOve时由于不停的调用BOxItem的get ...
- Think Python - Chapter 18 - Inheritance
In this chapter I present classes to represent playing cards, decks of cards, and poker hands.If you ...
- R处理xml文件
最近处理数据的时候需要处理一些xml文件,但是xml文件的格式之前并不是很熟悉.幸好R有一些函数可以帮助快速处理xml文件.其中的xmlToList函数尤其方便,可以使你从陌生的XML迅速回到熟悉的R ...
- asp.net网站 提示Ambiguous match found
在ASP.net中,每个aspx页面都会有一个.cs文件,(好像不可以多个aspx共用一个cs的,我前面就碰到这个问题), 在aspx页面中,我们会用到服务器控件,或html控件,这些控件的id命名时 ...
- iOS7中如何去除UINavigationbar下边的那条黑线
做项目过程中遇到要去掉导航栏下面的一条黑线,从网上找到的一个方法 默认UINavigationbar样式 准备用于替换的背景 替换后的效果 if ([self.navigationController ...
- DB2中的ROW_NUMBER() OVER()函数用法
ROW_NUMBER() OVER()大概有俩方面的作用 1,分页, 并返回分页结果集.2,是对数据进行处理 分组 db2的分页: select tmp.* from ( SELECT rownu ...
- css 属性积累
1. letter-spacing:6px; //属性增加或减少字符间的空白(字符间距) 2. cursor // 鼠标移上去的鼠标状态 属性值有: ...
- 225. Implement Stack using Queues
代码如下: class MyStack { // Push element x onto stack. Queue<Integer> queue=new ArrayDeque<> ...
- sqlite字符反向模糊查找
sqlite 一个短字符要去db里模糊查找时,可以用like 如select * from t_contact where uphone like '%1234%'; 但是当输入的字符串超过数据库里的 ...
- launch文件概述---1
摘要: 原创博客:转载请表明出处:http://www.cnblogs.com/zxouxuewei/ 资源链接:http://wenku.baidu.com/link?url=PhyN3C6ghqo ...