import java.io.File;
import java.io.FileInputStream;
public class Main {
public static void main(String[] args) {
String pathname = "helloworld//src//main//resources//ValidationMessages.properties";
try {
File file = new File(pathname);
System.out.println("[01] getPath():[" + file.getPath() + "]");
System.out.println("[02] getAbsolutePath():[" + file.getAbsolutePath() + "]");
System.out.println("[03] getParent():[" + file.getParent() + "]");
System.out.println("[04] getName():[" + file.getName() + "]");
FileInputStream fis = new FileInputStream(file);
// ファイルの読み込み処理
} catch (Exception e) {
e.printStackTrace();
}
}
}
出力例
[01] getPath():[helloworld\src\main\resources\ValidationMessages.properties]
[02] getAbsolutePath():[C:\Users\rurur\Downloads\sts-4.17.1.RELEASE\helloworld\src\main\resources\ValidationMessages.properties]
[03] getParent():[helloworld\src\main\resources]
[04] getName():[ValidationMessages.properties]