嘿伙计们我试图突破一个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;
}
}
}