Use File/FileInputStream/FileOutputStream.

public void testWithFIS() throws IOException{
File file=new File("Test.txt");
FileInputStream fis=new FileInputStream(file); System.out.println("total file size:"+fis.available()); int content;
while((content = fis.read()) != -1){
System.out.println((char)content);
} fis.close(); } public void testWithFISWrite() throws IOException{
File file=new File("Test.txt");
FileOutputStream fos=new FileOutputStream(file); for (int i = 0; i < 5; i++) {
fos.write((int)'x');
} fos.close(); }

FileReader/BufferedReader

FileWriter/BufferedWriter

    public void testWithBufferReader() throws IOException{
FileReader file=new FileReader("Test.txt");
BufferedReader br=new BufferedReader(file); String currentLine;
while((currentLine = br.readLine()) != null){
System.out.println(currentLine);
} br.close();
file.close();
} @Test
public void testWithBufferWriter() throws IOException{
FileWriter file=new FileWriter("Test.txt");
BufferedWriter writer= new BufferedWriter(file); String currentLine="hello, this is ross";
writer.write(currentLine);
writer.newLine();
writer.write("second line");
writer.close();
file.close();
}

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

  1. java文本文件读写

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

  2. JAVA核心技术I---JAVA基础知识(文本文件读写)

    一:java IO包概述 (一)Java读写文件,只能以(数据)流的形式进行读写 (二)java IO 包 –节点类:直接对文件进行读写 –包装类 • 转化类:字节/字符/数据类型的转化类 • 装饰类 ...

  3. Java IO读写中文各种乱码问题 【转】

    Java IO读写中文各种乱码问题 转自:http://blog.sina.com.cn/s/blog_484ab56f0101muzh.html java.io.*读写中文各种乱码,很费劲.不完全解 ...

  4. java 顺序 读写 Properties 配置文件

    java 顺序 读写 Properties 配置文件 支持中文 不乱码 java 顺序 读写 Properties 配置文件 ,java默认提供的Properties API 继承hashmap ,不 ...

  5. java StringBuffer读写文件

    java StringBuffer读写文件 StringBuffer的优势 较String:String每更新一次就会new一个新的对象出来,更新次数上去之后,内存开销太大.而StringBuffer ...

  6. java io读写文件

    java io读写文件相关阅读:http://www.cnblogs.com/wing011203/archive/2013/05/03/3056535.html public class DemoI ...

  7. JAVA多线程读写文件范例

    在写之前先声明,本文是基于之前在博客园网站上检索到的一份JAVA多线程读写文件的示例,我在写自己的程序时是在那位作者写的基础上做了改良,但已不记得原文的地址.如果有知情者,烦请帖出地址,我在此文上加入 ...

  8. Qt 学习之路 2(37):文本文件读写

    Qt 学习之路 2(37):文本文件读写 豆子 2013年1月7日 Qt 学习之路 2 23条评论 上一章我们介绍了有关二进制文件的读写.二进制文件比较小巧,却不是人可读的格式.而文本文件是一种人可读 ...

  9. java(IO)读写文件乱码转换UTF-8问题

    java(IO)读写文件乱码转换UTF-8问题 读取文件 String Content = ""; // 文件很长的话建议使用StringBuffer try { FileInpu ...

随机推荐

  1. js字符串和正则表达式中的match、replace、exec等函数详解

    正则并不是经常使用,而正则和字符串之间的函数关系又错综复杂,谁是谁的函数,又是怎么样的一种结果,往往我们是看一遍忘一遍,对此我是头疼不已,感觉自己是个笨蛋^_^. 为了以后不再查文档,特此把常用的函数 ...

  2. org.springframework.dao.DataIntegrityViolationException:

    数据库用的hibernate,开发工具用的myeclipse,使用开发工具连接数据库生成hibernate基于xml的po类,运行时报org.springframework.dao.DataInteg ...

  3. sqlserver数据库 Schema

    //读取数据库中所有的数据库 USE MASTER DECLARE @is_policy_automation_enabled bit SET @is_policy_automation_enable ...

  4. 运行第一个abp项目VS2015+localDB

    ASP.NET Boilerplate,简称ABP 详细深入:可以参考如下文章 http://www.cnblogs.com/mienreal/p/4528470.html http://www.cn ...

  5. svn小设置

    由于每次提交代码或者更新代码都需要输入密码,太不方便,今天请教了高手设置一下svn,问题解决... 流程如下  TortoiseSVN --> Settings -->  Network ...

  6. 七牛整合php上传从微信下载接口下载下来的文件

    因为ios系统直接读取不了MP3格式的文件,所以从微信接口下载下来的MP3格式音频上传到七牛后要转码.   Sample code:   public function doMobileUploadT ...

  7. NodeJS 调试工具(node-inspector)

    node-inspector是基于Chrome的调试工具. 安装: npm install -g node-inspector 1.启动node-inspector来监听node.js的debug调试 ...

  8. DragRow-GYF

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DragRowDemo.as ...

  9. ECMA中的switch语句

    switch借鉴自其他语言,但也有自己的特色. 1.可以在switch语句中使用任何数据类型(数值.字符串.对象等),很多其他语言中只能使用数值. 2.每个case的值不一定是常量,可以是变量或者表达 ...

  10. 在centos5开启telnet服务并验证

    1.安装telnet服务 [root@localhost ~]# yum install telnet 2.检查是否成功安装 [root@localhost ~]# rpm -qa | grep te ...