易截截图软件、单文件、免安装、纯绿色、仅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入门

 Java学习从入门到精通 
一、 JDK (Java Development Kit) 
JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具和Java基础的类库(rt.jar)。不论什么Java应用服务器实质都是内置了某个版本的JDK。因此掌握JDK是学好Java的第一步。最主流的J ......

java applet嵌入html页的正常显示问题

比如applet文件是AppletTest.class
1)
在AppletTest.java的代码中
使用默认包,即不用package语句
在html页中的代码是
<applet code="AppletTest.class" width="400" height="300">
</applet>
AppletTest.class文件和html页放在一个文件夹中
2)
在AppletTest.java的代码中
package xx.yy;
在html页 ......

Java与.NET谁是未来

 为什么会有Java,为什么会有.NET
  有人说,Java是为了跨Windows和UNIX而产生的。是这样吗?
  Sun有自己的操作系统solaris,并且打的是高端市场,而Java发展早期阶段,Windows还主
要定位在中小型企业,并没有打算与Sun一争高端客户。
  而且Sun的用户大部分都是大型企业级,而Windows定位在家庭消费用户, ......

从C++到Java的注意点(上)

   1.Java的编译运行 
       Java中的package概念相当于C++中的namespace的概念。但是java会把package的名字和文件系统中目录结构对应起来,也即如果你申明了某个package的名字为com.tij.everythingisobj,那么你的文件系统中必须创建com\tij\everythingisobj这样一个 ......

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[ ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号