This project is maven project
I want to read a file same package not resource directory
I know that below
- read a resource file in resource directory in maven structure
- when in runtime, Application read a file in target directory
and really know why directories (source, resource) are splitted.
But I wonder how to read a file in same package not in resource directory even if not formal (just curiosity)
FileIo.java
package hardlearner.springStudy.learningtest.io;
import java.io.IOException;
import java.io.InputStream;
public class FileIo {
public static void main(String[] args) throws IOException {
InputStream is = FileIo.class.getResourceAsStream("sample.txt");
if ( is == null) {
System.out.println("null");
}else {
System.out.println("not null");
System.out.println((char)is.read());
}
}
}
sample.txt
plz read me
FileIo.java
's main is working good on normal Java project but maven project isn't
And I checked working good if I copy sample.txt
file in same package (io package) in target directory
But not those, how can I read a file on same package in maven project?