Skip to content

Instantly share code, notes, and snippets.

/.sh

Created July 7, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9c700b511e5c9e1bb385 to your computer and use it in GitHub Desktop.
Save anonymous/9c700b511e5c9e1bb385 to your computer and use it in GitHub Desktop.
#this is the program
$cat Main.java
import java.util.stream.*;
import java.nio.file.*;
class Main {
public static void main( String ... args ) throws Exception {
String s = Files.lines(Paths.get("file.txt")).collect(Collectors.joining("\n"));
System.out.println(s);
}
}
#wc -c counts the number of characters in the file
$wc -c file.txt
14 file.txt
# od -c shows all the characters in the file (including invisible ones as line endings)
$od -c file.txt
0000000 h e l l o \r \n w o r l d \r \n
0000016
# if we run the program the output is modified
$java Main | wc -c
12
# we've got 12 instead of 14
# the \r was stripped
$java Main | od -c
0000000 h e l l o \n w o r l d \n
0000014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment