Skip to content

Instantly share code, notes, and snippets.

@janko
Last active September 30, 2018 08:09
Show Gist options
  • Save janko/5138791 to your computer and use it in GitHub Desktop.
Save janko/5138791 to your computer and use it in GitHub Desktop.
Java vs Ruby (#1) -- File reading.
// Java
import java.util.BufferedReader;
import java.util.FileReader;
import java.util.IOException;
String content = new String();
try {
BufferedReader reader = new BufferedReader(FileReader.new(filename));
String line;
while ((line = reader.readLine()) != null) {
content += (line + "\n");
}
reader.close();
}
catch(IOException exception) {
exception.printStackTrace();
}
# Ruby
content = File.read(filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment