added getData and readfromfile method to read the csv files

domainBranch
Emre Durak 2024-12-20 13:51:16 +01:00
parent 319dd29405
commit c7fcabd287
1 changed files with 27 additions and 0 deletions

View File

@ -22,4 +22,31 @@ public class HitoriMain extends JFrame implements AcrtionListener{
JButton[][] buttons = makeButtonArray(data);
GameGUI.paintGame(buttons, colors, madeMoves, data);
}
public static ArrayList<String> readFromFile(String path){
ArrayList<String> lines = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(path))) {
String line;
while ((line = reader.readLine()) != null) {
lines.add(line);
}
} catch (IOException e) {
e.printStackTrace();
}
return lines;
}
public static String[][] getData(String filepath, int rows) throws FileNotFoundException{
String filepath0 = filepath;
Scanner sc = new Scanner(new File(filepath0));
String[][] data = new String[rows][rows];
int rowInt = 0;
while (sc.hasNextLine() && rowInt < rows) {
String line = sc.nextLine();
data[rowInt] = line.split(",");
rowInt++;
}
sc.close();
return data;
}
}