RandomAccessFile - 系统找不到指定的路径

RandomAccessFile - System cannot find path specificied

美好的一天, 我一直在研究一个程序来计算和保存它们之间使用的训练和卡路里,但我已经跌入谷底。

这是我的 RandomAccessFile:

RandomAccessFile dat = new RandomAccessFile("training\"+lastTraining+".dat","rw");

没用。它returns我"The system cannot find path specified." 现在,我没有创建文件夹和文件,因为我希望程序创建它们。我究竟做错了什么?我已经在路径中尝试了各种斜杠,但没有任何效果。

谢谢!

您是否尝试过传递完整路径? 例如:而不是 "training\file.dat" 做 (Windows) "C:/path/to/file/file.dat" (Unix) "/path/to/file/file.dat" 编辑:请注意,您尝试放置文件的文件夹必须事先存在,因为 RandomAccessFile 不会创建它们并抛出 FileNotFoundException