Sir, i am working in a java application.On that application i have to access files from "My Documents". The problem is coming with windows version when i am using windows 7, it can be accessed as "Documents" folder but for windows XP it is "My Documents".
I am writing following code to access files from "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 could you suggest me a generic method, which can be applied for all the versions of Windows?
You can check for the operating system version and then use that to map the proper file name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With