get char and unget char : ungetc « File Directory « Ruby






get char and unget char


f = File.open("data", "r:binary") # Open data file for binary reads
c = f.getc                        # Read the first byte as an integer
f.ungetc(c)                       # Push that byte back
c = f.readchar                    # Read it back again

 

Related examples in the same category