Here you can find the source of loadFile()
public static String loadFile()
//package com.java2s; //License from project: Open Source License import javax.swing.*; import java.io.*; public class Main { public static String lastTouchedFileName = ""; private static String lastTouchedDirectory = null; public static String loadFile() { JFileChooser fileChooser = new JFileChooser(lastTouchedDirectory); fileChooser.setApproveButtonText("Load"); if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); lastTouchedFileName = selectedFile.getName(); lastTouchedDirectory = selectedFile.getParent(); return loadFile(selectedFile); }/*from w w w . j a v a 2s . c o m*/ return null; } public static String loadFile(File file) { BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); StringBuffer json = new StringBuffer(); String line = reader.readLine(); while (line != null) { json.append(line); line = reader.readLine(); } if (json.length() > 0) { return json.toString(); } else { System.out.println("File was empty. Could not load."); } } catch (Exception e) { e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { } } } return null; } }