易截截图软件、单文件、免安装、纯绿色、仅160KB

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")));
}
}


相关文档:

java内部类总结

 
          
定义在一个类内部的类叫内部类,包含内部类的类称为外部类。内部类可以声明public、protected、private等访问限制,可以声明为
abstract的供其他内部类或外部类继承与扩展,或者声明为static、final的,也可以实现特定的接口。static的内部类行为上象一 ......

全面掌握java枚举类型

枚举类型是JDK5.0的新特征。Sun引进了一个全新的关键字enum来定义一个枚举类。下面就是一个典型枚举类型的定义:
Java代码
public enum Color{   
    RED,BLUE,BLACK,YELLOW,GREEN   
}  
public enum Color{
RED,BLUE,BLACK,YELLOW,GREEN
}
显 ......

java环境变量

@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 ......

Java重复洗牌

 import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class ShuffleTest {
  public static void main(String args[]) {
    String simpsons[ ......

Java学习笔记13——正则表达式

 一、功能
     1、字符串的匹配
     2、字符串的查找
     3、字符串的替换
 二、Java中涉及的类
     java.lang.String类、java.util.regex.Matcher类、java.util.regex.Pattern类
三、初步了解
   & ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号