package net.tqm.view.action;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import net.tqm.view.FileUtil;
public class Extract
{
public static void act(JButton jbtnRuntimeFromLog)
{
jbtnRuntimeFromLog.addMouseListener( new MouseAdapter()
{
@Override
public void mousePressed( MouseEvent e )
{
fetchRunTimeFromConfig();
}
} );
}
private static void fetchRunTimeFromConfig()
{
File file = FileUtil.selectFile( "D:\\" );
if( file == null )
{
JOptionPane.showMessageDialog( null, "没有选择文件!" );
return;
}
BufferedReader reader = null;
try
{
System.out.println( "以行为单位读取文件内容,一次读一整行:" );
reader = new BufferedReader( new FileReader( file ) );
String tempString = null;
// 一次读入一行,直到读入null为文件结束
while( ( tempString = reader.readLine() ) != null )
{
String ss = null;
if( tempString.contains( "Run sql:" ) )
{
ss = tempString.substring( tempString.indexOf( "2014" ), tempString.indexOf( "DEBUG" ) )
+ tempString.substring( tempString.indexOf( "time:" ) )
+ spaceCount( tempString.substring( tempString.indexOf( "time:" ) ).length() )
+ tempString.substring( tempString.indexOf( "Run sql:" ), tempString.indexOf( "time:" ) );
System.out.println( ss );
}
}
reader.close();
}
catch( IOException e )
{
e.printStackTrace();
}
finally
{
if( reader != null )
{
try
{
reader.close();
}
catch( IOException e1 )
{
}
}
}
}
private static String spaceCount( int length )
{
String space = "";
for( int i = 0; i < 15 - length; i++ )
{
space += " ";
}
return space;
}
}
Extract
最新推荐文章于 2024-07-21 09:42:14 发布