Skip to content

Instantly share code, notes, and snippets.

@gileno
Last active August 29, 2015 14:01
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 gileno/9fd8bf78b79babe1e27f to your computer and use it in GitHub Desktop.
Save gileno/9fd8bf78b79babe1e27f to your computer and use it in GitHub Desktop.
Comparativo de Ler Arquivo
package com.mkyong.io;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class BufferedReaderExample {
public static void main(String[] args) {
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader("C:\\testing.txt"));
while ((sCurrentLine = br.readLine()) != null) {
System.out.println(sCurrentLine);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
arquivo = open("C:\\testing.txt")
print arquivo.read()
## a forma mais correta
with open("C:\\testing.txt") as arquivo:
print arquivo.read()
f = File.open("C:\\testing.txt", "r")
f.each_line do |line|
puts line
end
f.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment