Here you can find the source of setCurrentDirectory(JFileChooser fileChooser, String location)
public static void setCurrentDirectory(JFileChooser fileChooser, String location)
//package com.java2s; //License from project: Apache License import java.io.File; import javax.swing.JFileChooser; public class Main { public static void setCurrentDirectory(JFileChooser fileChooser, String location) { if (pointsToFile(location)) location = location.substring(0, location.lastIndexOf("\\")); File dir = new File(location); if (dir.exists()) fileChooser.setCurrentDirectory(dir); }// w ww . ja va 2s .co m private static boolean pointsToFile(String location) { if (location.lastIndexOf("\\") < location.lastIndexOf(".")) return true; return false; } }