Visualizzazione dei risultati da 1 a 7 su 7

Visualizzazione discussione

  1. #1

    Differenza tra CharArrayWriter e BufferedImputStream

    Sto cercando di capire le differenze tra BufferedRead e BufferedImputStream ma ho qualche dubbio:

    Mi sapreste spiegare le differenze tra questi due codici del mio libro?

    Codice PHP:
    package esempi_dal_libro;
    import java.io.*;
    public class 
    Esempio {
        public static 
    void main(String args[]) throws IOException 
            
    String s "~This is a © copyright symbol " 
              
    "but this is &copy not.\n"
            
    char buf[] = new char[s.length()]; 
            
    s.getChars(0s.length(), buf0); 
            
    CharArrayReader in = new CharArrayReader(buf); 
            
    int c
            
    boolean marked false
            try ( 
    BufferedReader f = new BufferedReader(in) ) 
            { 
              while ((
    f.read()) != -1) { 
                switch(
    c) { 
                case 
    '&'
                  if (!
    marked) { 
                    
    f.mark(32); 
                    
    marked true
                  } else { 
                    
    marked false
                  } 
                  break; 
                case 
    ';'
                  if (
    marked) { 
                    
    marked false
                    
    System.out.print("(c)"); 
                  } else 
                    
    System.out.print((charc); 
                  break; 
                case 
    ' '
                  if (
    marked) { 
                    
    marked false
                    
    f.reset(); 
                    
    System.out.print("&"); 
                  } else 
                    
    System.out.print((charc); 
                  break; 
                default: 
                  if (!
    marked
                    
    System.out.print((charc); 
                  break; 
                } 
              } 
            } catch(
    IOException e) { 
              
    System.out.println("I/O Error: " e); 
            } 
          }     


    Codice PHP:
    package esempi_dal_libro;
    import java.io.*;
    public class 
    Esempio {
        public static 
    void main(String args[]) { 
            
    String s "~This is a © copyright symbol " 
              
    "but this is &copy not.\n"
            
    byte buf[] = s.getBytes(); 
         
            
    ByteArrayInputStream in = new ByteArrayInputStream(buf); 
            
    int c
            
    boolean marked false
         
            
    // Use try-with-resources to manage the file. 
            
    try ( BufferedInputStream f = new BufferedInputStream(in) ) 
            { 
              while ((
    f.read()) != -1) { 
                switch(
    c) { 
                case 
    '&'
                  if (!
    marked) { 
                    
    f.mark(32); 
                    
    marked true
                  } else { 
                    
    marked false
                  } 
                  break; 
                case 
    ';'
                  if (
    marked) { 
                    
    marked false
                    
    System.out.print("(c)"); 
                  } else 
                    
    System.out.print((charc); 
                  break; 
                case 
    ' '
                  if (
    marked) { 
                    
    marked false
                    
    f.reset(); 
                    
    System.out.print("&"); 
                  } else 
                    
    System.out.print((charc); 
                  break; 
                default: 
                  if (!
    marked
                    
    System.out.print((charc); 
                  break; 
                } 
              } 
            } catch(
    IOException e) { 
              
    System.out.println("I/O Error: " e); 
            } 
          } 

    Ultima modifica di giannino1995; 28-10-2013 a 13:03

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.