The problem is that I need the file to move before the rest of my logic will work, so when the method returns false, I stop execution.
However, when I check the file in Windows Explorer, it has a new name and it moves.
Just curious why this is happening.
here is an example of the code that i was just trying to recreate. This is pretty much the same, and it works great.
File testfile = new File("TestFile"); if(!testfile.exists()){ testfile.mkdirs(); } File sample = new File("sample.txt"); if(sample.exists()){ boolean success = sample.renameTo(new File(testfile.getPath() + "\\" + sample.getName())); if(success){ System.out.println("Moved"); } else{ System.out.println("Failed"); } }
Edit: Decided. I apologize for spending all the time on something so stupid. However, I really do not think that I would have tracked this, if not for this.
The solution was that I actually iterated over several files to move. When the output indicated that this did not succeed, the program stopped, and when I looked in the explorer, only the first of the files was really moved, so I assumed that it moves, and then returns false. However, the problem was that I used the wrong variable as an index, and therefore it happened that it successfully moved the file to index 0, and then when the loop repeats, the index did not increase, so it tried to move index 0 again and therefore not managed.
As I said, itโs very stupid, but thank you for being with me.
Mason source share