代码之家  ›  专栏  ›  技术社区  ›  Jaimin Modi

Java中的mark()和reset()方法

  •  1
  • Jaimin Modi  · 技术社区  · 5 年前

    无效标记(int readlimit): PushbackInputStream的标记方法 什么都不做

    无效重置(): 将此流重新定位到上次对此输入流调用mark方法时的位置。 什么都不做 除了抛出一个IOException。

    '. 如果是这样,为什么 方法?

    import java.io.ByteArrayInputStream; 
    import java.io.IOException; 
    import java.io.PrintWriter; 
    import java.io.PushbackInputStream; 
    public class PushbackInputStreamDemo  
    { 
        public static void main(String arg[]) throws Exception 
        { 
            PrintWriter pw = new PrintWriter(System.out, true); 
            String str = "GeeksforGeeks a computer science portal "; 
            byte b[] = str.getBytes(); 
            ByteArrayInputStream bout = new ByteArrayInputStream(b); 
            PushbackInputStream push = new PushbackInputStream(bout); 
    
            int c; 
            while((c=push.read())!=-1) 
            { 
                pw.print((char)c); 
            } 
            pw.println(); 
    
            // marking the position  
            push.mark(5); 
    
            // reseting is not supported throw exception 
            push.reset(); 
    
            pw.close(); 
        } 
    } 
    

    上面是示例,但没有得到两种方法的确切含义 做。请引导。

    1 回复  |  直到 5 年前
        1
  •  3
  •   Thilo    5 年前

    这个 mark reset markSupported 看看是否有。

    PushbackInputStream不支持这些方法。

    InputStream 接口。也许是一个糟糕的设计决策(可以添加到一个单独的接口中),但事实就是如此。