为什么我的 break 标签出错了?
Why is my break label erroring?
嘿,伙计们,我正在尝试跳出搜索所有文件并在找到文件后中断的 for 循环。我发现的最好的事情是标签中断,但它给出了一个错误,说它不存在你们可以看看我做错了什么吗?
import java.nio.file.Files;
import java.nio.file.Paths;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.jaxen.dom4j.*;
public class Load
{
static String info = "";
public static String LoadSum(String projNum)
{
info = "";
try
{
searching:
Files.walk(Paths.get("D:/workspace/Project Program/Projects/")).forEach(filePath ->
{
if(Files.isRegularFile(filePath))
{
try
{
System.out.println("Checking");
SAXReader reader = new SAXReader();
Document document = reader.read(filePath.toFile());
Node node = document.selectSingleNode("//Project/Info/ProjectNumber");
String projectNumber = node.getStringValue();
if(projNum.equals(projectNumber))
{
System.out.println("Found it");
node = document.selectSingleNode("//Project/Info/Name");
info += node.getStringValue() + " : ";
//node = document.selectSingleNode("//Project/Info/Owner");
info += "Owner" + " : ";
node = document.selectSingleNode("//Project/Info/Status");
info += node.getStringValue() + " : ";
break searching; // error here searching doe not exist
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}
catch(Exception e)
{
e.printStackTrace();
}
return info;
}
}
}
嘿,伙计们,我正在尝试跳出搜索所有文件并在找到文件后中断的 for 循环。我发现的最好的事情是标签中断,但它给出了一个错误,说它不存在你们可以看看我做错了什么吗?
import java.nio.file.Files;
import java.nio.file.Paths;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.jaxen.dom4j.*;
public class Load
{
static String info = "";
public static String LoadSum(String projNum)
{
info = "";
try
{
searching:
Files.walk(Paths.get("D:/workspace/Project Program/Projects/")).forEach(filePath ->
{
if(Files.isRegularFile(filePath))
{
try
{
System.out.println("Checking");
SAXReader reader = new SAXReader();
Document document = reader.read(filePath.toFile());
Node node = document.selectSingleNode("//Project/Info/ProjectNumber");
String projectNumber = node.getStringValue();
if(projNum.equals(projectNumber))
{
System.out.println("Found it");
node = document.selectSingleNode("//Project/Info/Name");
info += node.getStringValue() + " : ";
//node = document.selectSingleNode("//Project/Info/Owner");
info += "Owner" + " : ";
node = document.selectSingleNode("//Project/Info/Status");
info += node.getStringValue() + " : ";
break searching; // error here searching doe not exist
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}
catch(Exception e)
{
e.printStackTrace();
}
return info;
}
}
}