import java.io.*; import java.awt.*; import java.awt.event.*; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; public class TestLogFile { public static void main(String[] args) throws FileNotFoundException, IOException { JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("Test Program"); frame.setPreferredSize(new Dimension(400,400)); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Select File"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { { JFileChooser fileChooser = new JFileChooser(); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { try { File selectedFile = fileChooser.getSelectedFile(); readFile(selectedFile.getPath()); } catch (FileNotFoundException ex) { Logger.getLogger(TestLogFile.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(TestLogFile.class.getName()).log(Level.SEVERE, null, ex); } } } } }); frame.add(button); frame.pack(); frame.setVisible(true); } public static void readFile (String path) throws FileNotFoundException, IOException { BufferedReader br = new BufferedReader(new FileReader(path)); String line; String[] subLine = new String[6]; String[] StrBR = new String[8]; PrintWriter writer = new PrintWriter("the-file-name.txt", "UTF-8"); StrBR[6]=""; while ((line = br.readLine()) != null) { if(line.contains("changed bitrate: ")) { StrBR=line.split(" "); float y = Float.parseFloat(StrBR[6]); y=y/1000000; StrBR[6] = Float.toString(y); } if(line.contains("[CurVideoInfo]")) { subLine=line.split(" "); System.out.println(subLine[3]+" "+subLine[4]+" "+ subLine[5]+ " ," + StrBR[6] ); writer.println(subLine[3]+" "+subLine[4]+" "+subLine[5] + " ," + StrBR[6]+"\n" ); } } writer.close(); br.close(); //System.exit(0); } }
yourFileChooser.setCurrentDirectory("Path");
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง