I have simple java code to select the file and return array.
When I use dedicated method (whole code below), my compilation (in IntelliJ) does not end -> it gets to the last lane of public static void main(String[] arg)
, it executes last lane System.out.println("Program ends.");
but I don't get information from compilator:
Process finished with exit code -1
import java.util.HashMap; //import the HashMap class
import java.io.File; // Import the File class
import java.io.FileNotFoundException; // Import this class to handle errors
import java.util.Scanner; // Import the Scanner class to read text files
import java.awt.FileDialog;
import java.awt.Frame;
public class Project1
{
public static void main(String[] arg)
{
HashMap<Integer, int[][]> dicUsedFuncs = new HashMap<Integer, int[][]>();
//import textfile with haskell code
String[] arrString=SelectFile();
System.out.println(arrString[0]);
System.out.println(arrString[1]);
//scan load
System.out.println("End");
}
private static String[] SelectFile()
{
String[] arrReturn = new String[2];
String strDefaultPath=System.getProperty("user.dir"); //default location to open
Frame frame = null;
FileDialog fd = new FileDialog(frame, "Please choose a text file with code.", FileDialog.LOAD);
fd.setDirectory(strDefaultPath);
fd.setFile("*.txt");
fd.setVisible(true);
String filename = fd.getFile(); //get just the selected file name
if (filename == null) {
arrReturn[0] = "NotSelected";
}else {
filename= new File(fd.getFile()).getAbsolutePath(); //get full file path of selected file
arrReturn[0] = "Selected";
arrReturn[1] = filename;
}
return arrReturn;
}
}
I added following:
library
import java.awt.Window;
loop to close all windows in method private static String[] SelectFile()
for (Window window : Window.getWindows()) { window.dispose(); }