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. 【KeyCode 键码】

    Key codes returned by Event.keyCode. These map directly to a physical key on the keyboard. KeyCode是由 ...

  2. AngularJs的UI组件ui-Bootstrap

    http://www.cnblogs.com/pilixiami/p/5597634.html

  3. 轮廓线DP POJ3254 && BZOJ 1087

    补了一发轮廓线DP,发现完全没有必要从右往左设置状态,自然一点: 5 6 7 8 9 1 2 3 4 如此设置轮廓线标号,转移的时候直接把当前j位改成0或者1就行了.注意多记录些信息对简化代码是很有帮 ...

  4. java常用英文解释

    java常用名词解释: OO: object-oriented ,面向对象 OOP:object-oriented programming,面向对象编程 Author:JCC Object:对象JDK ...

  5. Dashborad 上显示出错

    Dashboard 上显示的错误是因为没有选择对应的X-坐标. 上周处理过 一个字段,它是一个Formula 字段,作为Dashboard的 Data Source 前提是报表是得Group by 一 ...

  6. Manthan, Codefest 16 -A Ebony and Ivory

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  7. Xamarin.Forms listview中的button按钮,实现带着参数返回上一级页面

    今天在做列表显示的时候遇到一个问题,就是在ListView中如何才能让一个button的按钮工作并且包含参数呢? 其实有点类似于rep里的控件无法起获取一样.在Xamarin中,当你button绑定事 ...

  8. JavaScript的apply()方法和call()方法

    1 <script type="text/javascript"> 2 /*定义一个人类*/ 3 function Person(name,age) 4 { 5 thi ...

  9. webapi aspose导出excel表格

    API 通过get请求,注意用到一个[FromUri]特性,使GET接收实体参数 /// <summary> /// 导出 /// </summary> /// <par ...

  10. laravel框架总结(十) -- 返回值

    以前用CI框架对于返回值没有过多关注,但是发现使用laravel框架的时候出现了一些小问题,特意实践总结了一些常用情形,希望对大家有所帮助   先理解几个概念: 1>StdClass 对象=&g ...