zoukankan      html  css  js  c++  java
  • 利用PushbackReader读取文件中某个字符串之前的内容

    package File;
    
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.PushbackReader;
    
    
    /*读取文件中某个字符串之前的文件*/
    //PushbackInputStream,PushbackReader应用
    
    
    public class PushbackTest {
    	public static void main(String[] args) {
    		try(PushbackReader pr = new PushbackReader(new FileReader(
    								"./src/File/PushbackTest.java"),64))
    		{
    			char[] buf = new char[32];
    			String lastContent = "";
    			int hasRead = 0;
    			while((hasRead = pr.read(buf))>0)
    			{
    				String content = new String(buf,0,hasRead);
    				int targetIndex = 0;
    				
    				if((targetIndex = (lastContent + content).indexOf("new PushbackReader"))>0)
    				{
    					pr.unread((lastContent+content).toCharArray());
    					
    					if(targetIndex>32)
    					{
    						buf = new char[targetIndex];
    					}
    					pr.read(buf,0,targetIndex);
    					System.out.println(new String(buf,0,targetIndex));
    					System.exit(0);
    				}
    				else
    				{
    					System.out.println(lastContent);
    					lastContent = content;
    				}
    			}
    		}catch(IOException ioe)
    		{
    			ioe.printStackTrace();
    		}
    	}
    }
    
  • 相关阅读:
    《人月神话》读后感
    软件工程心得体会(十一)
    Arch + Win10 EFI 引导重装记录
    BurpSuite 的使用
    Wireshark 的使用
    Android 中的反调试技术
    IDA 对 so 的动态调试
    Smail 中的一些点
    IDA 对 SO 的逆向
    动态调试smali代码
  • 原文地址:https://www.cnblogs.com/masterlibin/p/4783996.html
Copyright © 2011-2022 走看看