While searching for how to do this, I found some vague discussion about different options, like JNI vs JNA, but not much in the way of concrete examples.
Context: if Java’s File.renameTo() cannot do it’s job (for whatever reason; it is a little problematic), I’d like to fall back to directly using this native Windows function, which is defined in kernel32.dll (from this answer):
BOOL WINAPI MoveFile(
__in LPCTSTR lpExistingFileName,
__in LPCTSTR lpNewFileName
);
So, using whatever approach, how exactly would you call that function from within Java code? I’m looking for the simplest way, with the minimum amount of non-Java code or extra steps (e.g. in compilation or deployment).
If you go with JNA, consider invoking MoveFileW directly – it saves having to provide configuration info to choose between Unicode and ANSI calls.
EDIT: I’ve edited my answer after checking the code – I was mistaken about using char[] in the signature – it is better to use WString.