Search code examples
javaiorandomaccessfile

RandomAccessFile - System cannot find path specificied


Good day, I've been working on a program for calculating and also saving trainings and calories used between them and I've hit rock bottom.

This is my RandomAccessFile:

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

It doesn't work. It returns me "The system cannot find path specified." Now, I don't have folder neither file created, because I want program to create them. What am I doing wrong? I already tried all kind of slashes in path but nothing works.

Thanks!


Solution

  • Have you tried passing in the full path? E.g: instead of "training\file.dat" do (Windows) "C:/path/to/file/file.dat" (Unix) "/path/to/file/file.dat" Edit: Note that the folder(s) you are trying to place the file in have to exist beforehand, as RandomAccessFile will not create them and throw the FileNotFoundException