배열 목록에 사용자를 추가 할 때이 코드를 파일에 쓸 수 있습니다. 코드는 잘 작동 :코드를 복제하지 않고 여러 파일에 쓰기 Java
public void writeToFile(String content)
{
try {
File file = new File("H:/JavaWorkspace/TradingPlatformProject/User_Report.txt");
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content + "\n");
bw.close();
logger.info("Recorded to User Activity file");
} catch (IOException e) {
e.printStackTrace();
}
}
내가 (권한 업그레이드를 요청, 말) 사용자가 다른 무언가를 할 때 별도의 파일에 기록합니다. 이 코드를 복제하지 않고 "UserRequests.txt"라는 새 파일에 쓸 수있는 방법이 있습니까?
아마도 파일 이름이나 작업을 매개 변수로 추가하면됩니까? –