사용자가 특정 폴더를 선택하고 해당 폴더의 모든 파일과 해당 개별 파일의 코드 줄을 계산하는 응용 프로그램이 있고 콘솔에서 파일 이름 및 그들에게 코드의 라인은 ..here의 코드 내 조각 표시됩니다 ...지도에서 읽은 총 행수를 표시합니다.
Map<String, Integer> result = new HashMap<String, Integer>();
File directory = new File(chooser.getSelectedFile().getAbsolutePath());
File[] files = directory.listFiles();
for (File file : files)
{
if (file.isFile())
{ Scanner scanner = new Scanner(new FileReader(file));
int lineCount = 0;
try
{ for (lineCount = 0; scanner.nextLine() != null; lineCount++) ;
} catch (NoSuchElementException e)
{ result.put(file.getName(), lineCount);
}
}
}
for (Map.Entry<String, Integer> entry : result.entrySet())
{ System.out.println(entry.getKey() + " ==> " + entry.getValue());
} }
하지만 난 그 6 개 개별 파일을 가정 할 수 있습니다 그것은 또한 모든 파일의 전체 행을 표시해야 하나 개 더 많은 기능을 추가 할 코드 줄 수를 10 줄로하고 각 줄의 합은 10 * 6입니다.이 줄은 60 줄입니다.이 방법을 알려주십시오.