Here you can find the source of importFile(JFileChooser jFileChooser)
public static String importFile(JFileChooser jFileChooser)
//package com.java2s; //License from project: Open Source License import javax.swing.*; import java.io.*; import java.util.ArrayList; public class Main { public static String importFile(JFileChooser jFileChooser) { StringBuilder stringBuilder; int result = jFileChooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { final ArrayList<String> parfileTextLines = myReadDataFile(jFileChooser .getSelectedFile().toString()); stringBuilder = new StringBuilder(); for (String currLine : parfileTextLines) { stringBuilder.append(currLine); stringBuilder.append("\n"); }/*from w w w .ja v a 2 s. c o m*/ return stringBuilder.toString(); } return null; } private static ArrayList<String> myReadDataFile(String fileName) { String lineData; ArrayList<String> fileContents = new ArrayList<String>(); BufferedReader moFile = null; try { moFile = new BufferedReader(new FileReader(new File(fileName))); while ((lineData = moFile.readLine()) != null) { fileContents.add(lineData); } } catch (IOException e) { ; } finally { try { moFile.close(); } catch (Exception e) { //Ignore } } return fileContents; } }