FileInputStream 讀取文件的絕對路徑和相對路徑

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文件在工程根目錄下

發佈了37 篇原創文章 · 獲贊 24 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章