Sir, I work in a Java application. In this application, I have to access files from My Documents. The problem occurs with the version of Windows, when I use Windows 7, it can be obtained in the Documents folder, but for Windows XP it is My Documents.
I am writing the following code to access files from the Documents folder in Windows 7.
public static void main(String[] arr) { try { String source = System.getProperty("user.home")+ File.separator + "Documents"; File[] Files = new File(source).listFiles(); System.out.println(Files.length); } catch(Exception ex) { ex.printStackTrace(); } }
and for windows xp
public static void main(String[] arr) { try { String source = System.getProperty("user.home")+ File.separator + "My Documents"; File[] Files = new File(source).listFiles(); System.out.println(Files.length); } catch(Exception ex) { ex.printStackTrace(); } }
Please, can you offer me a general method that can be applied to all versions of Windows?
java windows version
Toman
source share