问题:两个类尝试使用相同的代码访问两个不同的(相对)路径。
步骤:
sendAsJson:true
Client.java
getSchemaStatements()
SQLiteDB.java
,而在客户端设置为C:/WINDOWS/System32
班级C:\Users\<user>\git\x\y
:
client.java
班级public class Client {
@SuppressWarnings("unused")
private static TUI tui;
public static final String RELATIVE_PATH = Paths.get("").toAbsolutePath().toString();
public static void main(String[] args) {
System.out.println(RELATIVE_PATH);
// Prints C:\Users\user\git\x\y
// The above path is the correct path
tui = new TUI();
}
SQLiteDB.java
我在这里遗漏了什么吗?感谢您的帮助!
编辑:Stacktrace:public class SQLiteDB {
public static final String RELATIVE_PATH = Paths.get("").toAbsolutePath().toString();
public static void initializeDB() {
//<snip>
}
private static String getSchemaStatements() {
List<String> lines = null;
try {
System.out.println(RELATIVE_PATH); // Prints C:/WINDOWS/System32
System.out.println(Client.RELATIVE_PATH); // Now suddenly also prints C:/WINDOWS/System32 while it was set as C:\Users\user\git\x\y
lines = Files.readAllLines(schema);
} catch (IOException e) {
e.printStackTrace();
}
//<snip>
}