[英]How to read files from dist folder java
這可能是幾個人重復提出的問題,但是搜索答案后我聽不懂。
netbeans在生成操作之后創建一個文件夾dist。 我想在該文件夾中放置一個文本文件,jar文件應讀取該文本文件。
目標平台是Windows和Linux
文件夾的結構,
.java file = C:\My Documents\NetBeansProjects\Example\src\example
build folder = C:\My Documents\NetBeansProjects\Example
build folder contains classes folder. classes folder contains all the class files
dist folder = C:\My Documents\NetBeansProjects\Example
dist folder contains the .jar files and i want to place a text file inside this folder
的
getClass().getClassLoader().getResource("example.txt");
似乎僅在路徑與.java文件一起使用時才起作用。
謝謝
要從jar中讀取一些文件,您應該執行以下操作:
getClass().getResourceAsStream("path/to/file");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.