Special Directories

Get exe directory


	String exePath = new File(getClass().getResource("").getPath()).getParentFile().getParent();
	//Gives:
	//	"file:C:Program Files (x86)My App DirectoryMy App Name 2.2.4libmymodulename.jar!comname"

	int index = exePath.lastIndexOf("\lib\mymodulename.jar!\com\name");
	if (index > 0)
		exePath = exePath.substring(0, index);

Working With Directories

Create Directory


	boolean exists = (new File("C:/downloads/mydir")).exists();
	if (!exists)
		new File("C:/downloads/mydir").mkdirs();

Working with files

Delete File And Parent Directories If Now Empty


	//Delete file
	boolean success = (new File(outputPath)).delete();
	if (success)
	{
		//Delete empty parent directories
		int index;
		File file;
		while(true)
		{
			index = outputPath.lastIndexOf("/");
			if (index < 1) 				break; 			outputPath = outputPath.substring(0, index); 								 			if (outputPath.length() == 0) 				break; 			 			file = new File(outputPath); 			if (!file.isDirectory()) 				break; 			 			if (file.list().length > 0)
			{
				break;					//There are files - all done
			}

 (more...)