#BufferedReader
1 messages · Page 1 of 1 (latest)
Detected code, here are some useful tools:
I uploaded your attachments as Gist.
<@&987246717831381062> please have a look, thanks.
Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
code:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
String[][] array = new String[3][3];
try (BufferedReader br = new BufferedReader(new FileReader("input.txt"))) {
String line;
int row = 0;
while ((line = br.readLine()) != null) {
String[] values = line.split(",");
for (int col = 0; col < values.length; col++) {
array[row][col] = values[col];
}
row++;
}
} catch (IOException e) {
e.printStackTrace();
}
// Print the array
for (String[] row : array) {
for (String value : row) {
System.out.print(value + " ");
}
System.out.println();
}
}
}
Make sure you have a file named "input.txt" in the same directory as your Java file, and it should contain the data you want to convert into a 2D array. Each line in the file should represent a row in the array, and values should be separated by commas.
For example, if your "input.txt" file contains:
1,2,3
4,5,6
7,8,9
The output will be:
1 2 3
4 5 6
7 8 9
um... well that worked