I want to read a text from a file. Every line should be split at 180 characters and then each line should be added to a table, but I get the error message "String index out of range -180".
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class ReadAndWrite {
public static void main(String[] args) throws IOException {
BufferedReader read = new BufferedReader (new FileReader("xyz.txt"));
String line = read.readLine();
int len = line.length();
System.out.println(len);
int chaCount = 0;
while (chaCount < len) {
String line2 = line.substring(chaCount, 180);
System.out.println(line2);
chaCount += 180;
}
}
}