I built a JavaFX project that is supposed to read .txt files into TextArea and when I run the project inside IntelliJ, everything works properly, But when I do Artifact, the .jar can't find the requested file. Which way can you get the .jar file to read the .txt file after exporting?
My JavaFX Controller looks like this:
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXComboBox;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextArea;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Controller {
ObservableList<String> days = FXCollections.observableArrayList
("1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30"),
months = FXCollections.observableArrayList
("Tishrei", "Cheshvan", "Kislev", "Tevet", "Shevat", "Adar",
"Nisan", "Iyar", "Sivan", "Tammuz", "Av", "Elul");
public JFXComboBox day, month;
public JFXButton ok;
public ScrollPane scrollPane;
public TextArea textArea;
@FXML
private void initialize(){
day.setItems(days);
month.setItems(months);
}
public void okClick() {
String dayValue = (String) day.getValue();
String monthValue = (String) month.getValue();
File dayFile = new File("src/textFiles/days/"+dayValue+".txt");
File monthFile = new File("src/textFiles/months/"+monthValue+".txt");
String dayTitle = ("Day " + dayValue + ":\n");
String monthTitle = ("Month " + monthValue + ":\n");
try {
String scanDayFile = new Scanner(dayFile).useDelimiter("\\Z").next();
String scanMonthFile = new Scanner(monthFile).useDelimiter("\\Z").next();
textArea.setText(dayTitle + scanDayFile + "\n\n" + monthTitle + scanMonthFile);
}
catch (FileNotFoundException e){
System.out.println("file not found");
}
}
}
Thanks in advance for any help you can give.