Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在处理文件时,如果行与行之间有空字符串,而不是文件末尾有空字符串,则中断进程_Java - Fatal编程技术网

Java 在处理文件时,如果行与行之间有空字符串,而不是文件末尾有空字符串,则中断进程

Java 在处理文件时,如果行与行之间有空字符串,而不是文件末尾有空字符串,则中断进程,java,Java,在用Java读取文件时,如果中间有空行,我应该中断这个过程。但如果空行位于文件末尾,则应忽略此条件 while ((line = reader.readLine()) != null) { if (line == null || line.trim().length() <= 0) { log.debug("Terminating on first blank line");// terminate on first blank line empty

在用Java读取文件时,如果中间有空行,我应该中断这个过程。但如果空行位于文件末尾,则应忽略此条件

while ((line = reader.readLine()) != null) {
    if (line == null || line.trim().length() <= 0) {
        log.debug("Terminating on first blank line");// terminate on first blank line
        empty_line = true;                                
        break;
    }
}
while((line=reader.readLine())!=null){

如果(line==null | | line.trim().length()在读取空行后读取非空行时,必须中断进程

bool blankLineRead = false;
while ((line = reader.readLine()) != null) {
    //Inside the cicle line is surely not null
    if (line.trim().lenght() <= 0)
        blankLineRead = true;
    else
        if (blankLineRead) {
            log.debug("Terminating on first blank line");// terminate on first blank line
            break;
        }
}
bool blankLineRead=false;
而((line=reader.readLine())!=null){
//在圆线内肯定不是空的

如果(line.trim().lenght()在读取空行后读取非空行时,必须中断该过程

bool blankLineRead = false;
while ((line = reader.readLine()) != null) {
    //Inside the cicle line is surely not null
    if (line.trim().lenght() <= 0)
        blankLineRead = true;
    else
        if (blankLineRead) {
            log.debug("Terminating on first blank line");// terminate on first blank line
            break;
        }
}
bool blankLineRead=false;
而((line=reader.readLine())!=null){
//在圆线内肯定不是空的

如果(line.trim().lenght())使用此代码:您不能。每个
readLine
只会给您文件中的下一行。您无法提前知道下一个
readLine
是否会导致“达到文件结尾”状态。使用此代码:您不能。每个
readLine
只会给您文件中的下一行。您无法提前知道下一个
readLine
是否会导致“已达到文件结束”状态。