File Handling & new class

This commit is contained in:
FUH22860 2022-05-19 14:31:57 +02:00
parent 0f00467962
commit bfe88db9c4
2 changed files with 55 additions and 7 deletions

View File

@ -0,0 +1,16 @@
package application;
import java.util.ArrayList;
public class Graph {
private ArrayList<ArrayList<Graph>> values;
public Graph() {
values = new ArrayList<ArrayList<Graph>>();
}
public boolean receiveValues() {
return true;
}
}

View File

@ -1,6 +1,8 @@
package application;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import javafx.scene.Scene;
import javafx.scene.control.Button;
@ -46,14 +48,44 @@ public class RootBorderPane extends BorderPane {
btImport.setOnAction(event -> importCSV());
}
private void importCSV() {
public void importCSV() {
String extension = "";
FileChooser fileChooser = new FileChooser();
File selectedFile = fileChooser.showOpenDialog(null);
if (selectedFile != null) {
File Readfile = selectedFile;
if (Readfile.exists()) {
String FileName = Readfile.getName();
String FilePath = Readfile.getAbsolutePath();
int index = FileName.lastIndexOf('.');
if (index > 0) {
extension = FileName.substring(index + 1);
}
System.out.println(extension);
} else {
System.out.println("The file does not exist.");
}
if(extension == "txt") {
try {
File file = selectedFile;
Scanner myReader = new Scanner(file);
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
System.out.println(data);
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
} else {
System.out.println("The file is not a csv file.");
}
}
}
}