代码拉取完成,页面将自动刷新
修改方法
public static int rowCount(String str, Feature... features) throws IOException {
try (CSVReader state = new CSVReaderUTF8(features)) {
state.rowCount(str, str.length());
return state.rowCount();
} catch (Exception e) {
// 处理异常
e.printStackTrace();
throw e;
}
// try-with-resources会自动关闭资源
}
public static int rowCount(byte[] bytes, Feature... features) {
try (CSVReaderUTF8 state = new CSVReaderUTF8(features)) {
state.rowCount(bytes, bytes.length);
return state.rowCount();
} catch (Exception e) {
// 处理异常
e.printStackTrace();
throw e;
}
// try-with-resources会自动关闭资源
}
public static int rowCount(char[] chars, Feature... features) {
try (CSVReaderUTF16 state = new CSVReaderUTF16(features)) {
state.rowCount(chars, chars.length);
return state.rowCount();
} catch (Exception e) {
// 处理异常
e.printStackTrace();
throw e;
}
// try-with-resources会自动关闭资源
}
public static int rowCount(InputStream in) throws IOException {
if (in == null) {
throw new IllegalArgumentException("InputStream cannot be null");
}
try (CSVReaderUTF8 state = new CSVReaderUTF8()) {
byte[] bytes = new byte[SIZE_512K];
while (true) {
int cnt = in.read(bytes);
if (cnt == -1) {
break;
}
state.rowCount(bytes, cnt);
}
return state.rowCount();
} catch (Exception e) {
// 处理异常
e.printStackTrace();
throw e;
}
}