我对java奇怪的行为感到很困惑。
我的代码是;
public class Main {
private static String KK_PATH = "C:\\Users\\ahopyar\\Desktop\\kk.txt";
private static String EXCELL_PATH = "C:\\Users\\ahopyar\\Desktop\\kk.txt";
static List<User> users = new ArrayList<>();
public static void main(String[] args) throws EncryptedDocumentException, InvalidFormatException, IOException {
readExcell();
}
private static void readExcell() throws EncryptedDocumentException, InvalidFormatException, IOException {
File file = new File(KK_PATH);
System.out.println(file.exists());
}
}
如果我运行此代码,则打印“true”,但如果我将File file = new File(KK_PATH);
更改为File file = new File(EXCELL_PATH);
则会打印为false。
如何实现这一目标以及如何解决? (“C:\ Users \ ahopyar \ Desktop \ kk.txt”中有文件)