それはあなたのいずれかが必要のように聞こえる:
if (file.exists() && readFileAndCheckForWhatever(file)) {
// File exists and contains the relevant word
} else {
// File doesn't exist, or doesn't contain the relevant word
}
または
if (file.exists()) {
// Code elided: read the file...
if (contents.contains(...)) {
// File exists and contains the relevant word
} else {
// File exists but doesn't contain the relevant word
}
} else {
// File doesn't exist
}
またはそれに
if (!file.exists()) {
// File doesn't exist
} else if (readFileAndCheckForWhatever(file)) {
// File exists and contains the relevant word
} else {
// File exists but doesn't contain the relevant word
}
ファイルを開いて読み取ります。存在しない場合は例外が発生します。その後、ファイルが開いたら、それを読んで行を探します。 代わりに、コマンドラインからgrepだけを入力してください;-) –