FileInputStream 读取文件的绝对路径和相对路径 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public class InOutDemo { public static void main(String[] args) throws Exception { System.out.println(new File(".").getAbsolutePath()); InputStream is = new FileInputStream("g:\\1.txt"); //InputStream is = new FileInputStream(".\\src\\cn\\linson\\io\\2.txt"); //InputStream is = new FileInputStream(".\\config.properties"); int len = 0; byte[] b = new byte[10]; while((len = is.read(b))!= -1){ for(byte bb:b){ System.out.print((char)bb+" "); } } } } 1,绝对路径 2,相对路径 2.txt在包下 3,config文件在工程根目录下