|
| 1 | +package readtextfile; |
| 2 | +import java.io.IOException; |
| 3 | +import java.nio.charset.Charset; |
| 4 | +import java.nio.charset.StandardCharsets; |
| 5 | +import java.nio.file.Path; |
| 6 | +import java.nio.file.Paths; |
| 7 | +import java.util.Scanner; |
| 8 | + |
| 9 | +public class ReadTxt { |
| 10 | + final static String FILE_NAME = "C:\\Users\\Gopal\\Desktop\\infosys.txt"; |
| 11 | + final static Charset ENCODING = StandardCharsets.UTF_8; |
| 12 | + //static Path path = Paths.get(FILE_NAME); |
| 13 | + |
| 14 | + public static void main(String[] args) throws IOException { |
| 15 | + ReadTxt text = new ReadTxt(); |
| 16 | + text.readFile(FILE_NAME); |
| 17 | + } |
| 18 | + |
| 19 | + public void readFile(String aFileName)throws IOException{ |
| 20 | + Path path = Paths.get(aFileName); |
| 21 | + try(Scanner sc = new Scanner(path,ENCODING.name())){ |
| 22 | + while(sc.hasNextLine()){ |
| 23 | + String str = sc.nextLine(); |
| 24 | + |
| 25 | + /*ERM Device*/ |
| 26 | + if(str.contains("$SLU")){ |
| 27 | + str = str.substring(str.indexOf("$SLU"), str.indexOf("#")); |
| 28 | + System.out.println(str.substring(4,19)); |
| 29 | + //System.out.println(str); |
| 30 | + } |
| 31 | + //SUN100 Device |
| 32 | + if(str.contains("Recieved packet:")){ |
| 33 | + str = str.substring(str.indexOf("$SUN"), str.indexOf("|#")); |
| 34 | + System.out.println(str.substring(str.length()-15, str.length())); |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | +} |