我有以下代碼閱讀資源最終空
System.out.println("Path::: "+path);
InputStream resource = this.getClass().getResourceAsStream(path);
現在的路徑是: 的src /資源/ FF/1-Battle.mp3
這是我的文件夾結構:
src
|- resources
| |- FF
| | |- 1-Battle.mp3
|- folder
| |- prog.java <- this is the place where the code is run
的問題是資源(輸入流)已經結束了空
這需要工作從一個jar文件,所以我需要它是相對的jar文件根目錄directoy不是硬盤目錄,因此我不能創建一個文件,因爲在一個jar文件裏,這些文件不能分類在java.io.File下
你能證明你的變量'path'請 – Rob 2013-03-10 09:46:48
嘗試改變從'SRC /資源/ FF/1-Battle.mp3'到'/ src目錄/資源/ FF/1-戰役的路徑? mp3'即從斜槓開始,表示您正在從項目根目錄搜索 – tmwanik 2013-03-10 09:56:58
根目錄需要是相對的,以/開始從硬盤根目錄開始的路徑開始,因此我需要知道位置的jar文件 – mangusbrother 2013-03-10 11:20:09