Java读取文件(以后继续添加)
package cf.java.study.java.io;
import java.io.File;
import java.io.FileInputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class FileTests {
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Before
public void startTest() {
System.out.println(" Test Start " + StringUtils.repeat("-", 10));
}
@After
public void endTest() {
System.out.println('\n' + StringUtils.repeat("-", 10) + " Test End \n");
}
@Test
public void readDir() throws Exception {
File file = new File("/");
System.out.println("file: \n" + file);
// list the items in the directory
for (String str : file.list()) {
System.out.println(str);
}
}
@Test
public void readFile() throws Exception {
File file = new File("./test");
// make a FileInputStream with the file instance
FileInputStream fis = new FileInputStream(file);
// read the bytes from fis
// it is the end of file when read() returns -1
for (int re = 0; re >= 0; re = fis.read()) {
System.out.print((char)re);
}
fis.close();
}
@Test
public void readFileByApache() throws Exception {
// are you crazy?? can you be more simplier?
System.out.print(FileUtils.readFileToString(new File("./test")));
}
}
相关文档:
1. 预先加载与依需求加载
Java 运行环境为了优化系统,提高程序的执行速度,在 JRE 运行的开始会将 Java 运行所需要的基本类采用预先加载(
pre-loading )的方法全部加载要内存当中,因为这些单元在 Java 程序运行的过程当中经常要使用的,主要包括 JRE 的
rt.jar 文件里面所有的 .class 文 ......
整合Flex和Java—配置篇
Author:yongtree
废话就不说了,要想了解Flex的相关内容就请问一下Google,百度吧。切入正题,作为一个Java程序员学习Flex,关心的就是怎样将Flex和Java进行结合交互。带着Java程序员的思维,一开始学习Flex并没有按部就班的学习Flex的基础知识,而是想搞清楚Flex到底怎样和Java交互的。经过 ......
我的java学习了一年有余,起初是胡乱学,后来觉得java非常有意思,并且想在这方面深入学习,现在才是Java学习真正的开始。我正在阅读corejava和编程思想,学完这三本后想搞j2ee的开发。本人对数据库也感兴趣,现在热衷于SQL,但是我相信自己最终会瞄准ORECAL(很大程度出于好奇心),其实现在觉得Java DB ......
@echo off&setlocal enabledelayedexpansion
:begin
cls
set/p path_=请输入你要添加的环境变量的路径:
if not defined path_ goto error
for,/f,"skip=4 tokens=1,2,*",%%a,in,('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Sess ......
一、功能
1、字符串的匹配
2、字符串的查找
3、字符串的替换
二、Java中涉及的类
java.lang.String类、java.util.regex.Matcher类、java.util.regex.Pattern类
三、初步了解
& ......