0
我知道还有其他问题,但是即使使用这些代码,我也找不到代码中的错误。 我写了这个来检查在我的textField中写入的内容是否是一个路径,但它似乎是不正确的。这里的代码:Java正则表达式与路径
textFieldNewGameUrl.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent arg0) {
boolean isMatched = (textFieldNewGameUrl.getText()).matches("([a-zA-Z]:)?(\\\\[a-zA-Z0-9_.-]+)+\\\\?");
if(isMatched){
labelNewGameFeedback.setText("Ok, the path is correct");
}
else{
labelNewGameFeedback.setText("Strange things have happened : check the path.");
}
}
});
什么是预期输入和行为? –
'不正确'是什么意思? – locoyou
所以你想检查一个窗口路径的正确性。在你看来,是一个由“NUL”组成的路径有效吗?另见[这个问题/答案集](http://stackoverflow.com/questions/468789/is-there-a-way-in-java-to-determine-if-a-path-is-valid-without -attempting至CRE)。换一种说法;试着打开文件,看看会发生什么。 –