"Ruby is so much better than Java! Look at how you open a file in Java (shows you 30 lines) vs. Ruby! (2 lines)"
Ruby Example.
================
begin
File.open("/path/to/your/file.txt", "r") do |file|
file.each_line do |line|
puts line
end
end
rescue Errno::ENOENT
puts "File not found"
rescue Exception => e
puts "An error occurred: #{e.message}"
end
Java Example, one line less than Ruby ( no imports shown but could also be required for external Gems )================
public class Main {
public static void main(String[] args) {
String filePath = "/path/to/your/file.txt";
try (Stream<String> lines = Files.lines(Paths.get(filePath))) {
lines.forEach(System.out::println);
} catch (IOException e) {
e.printStackTrace();
}
}
}