Answer the question
In order to leave comments, you need to log in
How to specify the path to a file?
I am creating a project. In the project folder I create a folder resources. In this folder I throw the file test. How can I access this file without specifying the full path in the root system, but starting only from the project folder?
Answer the question
In order to leave comments, you need to log in
The construction
will give the full path to the current class file. You can use something like
public class Main {
void run() {
String testFilePath = getResourcePath("test");
System.out.println(testFilePath);
}
String getResourcePath(String file) {
return getClass().getResource("/").getPath() + "../resourses/" + file;
}
public static void main(String[] args) {
new Main().run();
}
}
getResourceAsStream()
You can do this:
in index.php
define ('RESOURSES', 'path/to/');
require_once(RESOURSES. "test.php");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question