Untitled
unknown
plain_text
a year ago
1.3 kB
1
Indexable
Never
import java.util.*; import java.io.File; import java.io.BufferedReader; import java.nio.charset.Charset; import java.nio.file.Files; import java.io.IOException; public class Main { public static List<String> getMessages(String pathName, String username){ File file = new File(pathName); List<String> myMessages = new ArrayList<String>(); Charset charset = Charset.forName("US-ASCII"); try (BufferedReader reader = Files.newBufferedReader(file.toPath(), charset)) { String line = null; while ((line = reader.readLine()) != null) { if (line.contains(username)){ String[] datos = line.split("->"); myMessages.add(datos[1]); } } //myMessages.forEach( (elem) -> System.out.println(elem)); } catch (IOException x) { System.err.format("IOException: %s%n", x); } return myMessages; } public static void main(String[] args) throws Exception { List<String> messages = getMessages("myMessages.txt", "@SergioRa"); messages.forEach( (elem) -> System.out.println(elem)); } }