Last active
August 29, 2015 14:01
-
-
Save gileno/9fd8bf78b79babe1e27f to your computer and use it in GitHub Desktop.
Comparativo de Ler Arquivo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arquivo = open("C:\\testing.txt") | |
print arquivo.read() | |
## a forma mais correta | |
with open("C:\\testing.txt") as arquivo: | |
print arquivo.read() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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