我想從文件中讀取文本。每行應分爲180個字符,然後每行應添加到表中,但我收到錯誤消息「字符串索引超出範圍-180」。帶有while循環的子串
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;
}
}
}
你是什麼意思'應該除以180個字符? –
我想「分裂」。 –