3、看看完整的测试代码
package com.lavasoft.test;
import java.io.*;
/**
* Java读取相对路径的文件
*
*/
public class ReadFile {
public static void main(String[] args) {
readTextA_ByClassPath();
readTextA_ByProjectRelativePath();
readTextB_ByProjectRelativePath();
}
/**
* 通过工程相对路径读取(包内)文件,注意不以“/”开头
*/
public static void readTextA_ByProjectRelativePath() {
System.out.println("-----------------readTextA_ByProjectRelativePath---------------------");
File f = new File("src/com/lavasoft/res/a.txt");
String a = file2String(f, "GBK");
System.out.println(a);
}
/**
* 通过工程相对路径读取(包外)文件,注意不以“/”开头
*/