Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.io.*;
- import java.io.File;
- public class zad3 {
- public static void main(String[] args) {
- System.out.println("Zadanie 3:");
- String text="";
- try {
- FileInputStream fis = new FileInputStream("Z:\\PPJ\\cw27\\serverLog.txt");
- int b = 0;
- while ((b = fis.read()) != -1) {
- //System.out.print((char) b);
- text=text+(char)b;
- }
- }
- catch (Exception e) {
- System.out.print(e);
- }
- String text1 = text;
- String text2=" ";
- String regex1 = "([0-9]{1,3}\\.){3}[0-9]{1,3}";
- Pattern p1 = Pattern.compile(regex1);
- Matcher m1 = p1.matcher(text1);
- System.out.println(m1.matches());
- while(m1.find()){
- text2=text2+m1.group()+"\n";
- }
- System.out.println(text2);
- String text3="";
- String regex2 = "[0-9]{1,3}";
- Pattern p2 = Pattern.compile(regex2);
- Matcher m2 = p2.matcher(text2);
- System.out.println(m2.matches());
- while(m2.find()){
- System.out.println(m2.group());
- text3=text3+Integer.toHexString(Integer.valueOf(m2.group()))+".";
- }
- System.out.println(text3);
- String text4="";
- String regex3 = "(\\w{1,2}\\.){3}\\w{1,2}";
- Pattern p3 = Pattern.compile(regex3);
- Matcher m3 = p3.matcher(text3);
- System.out.println(m3.matches());
- int i=1;
- while(m3.find()){
- System.out.println(m3.group());
- text4=text4+i+"\t"+m3.group()+"\n";
- i=i+1;
- }
- System.out.println(text4);
- File file = new File("Z:\\PPJ\\cw27\\log2.txt");
- try (FileOutputStream fop = new FileOutputStream(file)) {
- if (!file.exists()) {
- file.createNewFile();
- }
- byte[] byte1 = text4.getBytes();
- fop.write(byte1);
- fop.flush();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement