Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.*;
- public class Chatlogs {
- private static final DateFormat FORMAT = new SimpleDateFormat("yyyy MMM dd hh:mm:sss");
- public static void main(String... args) {
- try {
- BufferedWriter bw;
- bw = new BufferedWriter(new FileWriter("C:/java/writetohere.txt"));
- bw.write(readFile(new File("C:/java/readfromhere.txt").getAbsolutePath()));
- bw.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- private static String readFile(String path) throws IOException {
- ArrayList<String> list = new ArrayList<String>();
- FileInputStream fstream = new FileInputStream(path);
- DataInputStream in = new DataInputStream(fstream);
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- String strLine;
- StringBuilder sb = new StringBuilder();
- while ((strLine = br.readLine()) != null) {
- if (!strLine.contains("**** LOGGEN") && !strLine.contains("**** LOGGING") && !strLine.equals("")) {
- list.add(strLine);
- }
- }
- br.close();
- in.close();
- fstream.close();
- List<LogEntryComparator> entries = new LinkedList<LogEntryComparator>();
- Date date = null;
- for (String line : list) { //list is an arraylist of strings.
- String time = "2011 " + line.substring(0, 15);
- try {
- date = FORMAT.parse(time);
- } catch (Exception e) {
- e.printStackTrace();
- }
- entries.add(new LogEntryComparator(date, line.substring(15)));
- }
- Collections.sort(entries);
- for (int i = 0; i < entries.size(); i++) {
- System.out.println(entries.get(i).time + entries.get(i).entry);
- }
- return sb.toString();
- }
- }
- readfromhere.txt:
- jul 31 17:09:50 <phl0w> tes
- jul 31 17:10:49 <Andy_> Speed
- jul 31 17:10:51 <Andy_> lol Speed
- jul 31 19:20:50 <phl0w> lolfile1
- jul 29 17:09:50 <phl0w> tes
- jul 31 17:08:49 <yyyy> alewrwae
- jul 31 17:11:51 <xxxx> wrkjaer
- jul 31 19:20:53 <phl0w> lolfile3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement