Dobry wieczór,
przychodzę z zapytaniem, w jaki sposób mogę wczytać losową linijkę pliku txt tak aby wyświetlił pod adresem localhost : 8080 / motto
Tekst wpisany w kod już czyta.
@RequestMapping("/motto")
public class Controller {
public static String read() throws Exception {
File file = new File("/ala.txt");
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
ArrayList<String> arrayList = new ArrayList<>();
String line;
while ((line = bufferedReader.readLine()) != null) {
arrayList.add(line);
}
Random random = new Random();
return arrayList.get(random.nextInt(arrayList.size()));
}
}