My favorites | Sign in
Project Logo
                
Show all Featured downloads:
WinFoldersJava-1.0.zip
People details
Project owners:
  tomovo

This small interface library for Java will allow your Java program to access the Win32 API call SHGetSpecialFolderPath without using Swing (see below for the Swing method). This call gives you the locations of system folders such as 'My documents', 'Application data' and others. Comprises of a tiny Jar and a DLL file. Just include these in your project and you're ready.

How to use:

import com.catnapgames.winfolders.WinFoldersJava;

public static void main( String[] args ) {
	System.load( new File( "" ).getAbsolutePath() + "\\WinFoldersJava-1.0.dll" );
	System.out.println( "CSIDL_PERSONAL\t\t" + getSpecialFolderPath( CSIDL_PERSONAL ) );
	System.out.println( "CSIDL_LOCAL_APPDATA\t" + getSpecialFolderPath( CSIDL_PERSONAL ) );
	System.out.println( "CSIDL_MYPICTURES\t" + getSpecialFolderPath( CSIDL_MYPICTURES ) );
	System.out.println( "CSIDL_COMMON_APPDATA\t" + getSpecialFolderPath( CSIDL_COMMON_APPDATA ) );
	System.out.println( "CSIDL_COMMON_DOCUMENTS\t" + getSpecialFolderPath( CSIDL_COMMON_DOCUMENTS ) );
}

You may ask 'why not just get the java user.home property and append Desktop or My documents to that?'. Well, that may work in the English version of Windows, but in other languages, Windows names the folders differently. Also, Vista has a different folder structure compared to WinXP. Calling the aforementioned API function is necessary to get the correct folder location.

Also, if you need only the "My documents" path and don't mind touching Swing you may not need WinFoldersJava. You can use javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory() instead.









Hosted by Google Code