public class BufferedReaderDemo {
public static void main(String[] args) throws Exception {
String thisLine = null;
try {
// open input stream test.txt for reading purpose.
BufferedReader br = new BufferedReader("c:/test.txt");
while ((thisLine = br.readLine()) != null) {
System.out.println(thisLine);
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
class cat {
public static void main(String args[]) {
String thisLine;
// Loop across the arguments
for (int i = 0; i < args.length; i++) {
// Open the file for reading
try {
BufferedReader br = new BufferedReader(new FileReader(args[i]));
while ((thisLine = br.readLine()) != null) { // while loop begins here
System.out.println(thisLine);
} // end while
} // end try
catch (IOException e) {
System.err.println("Error: " + e);
}
} // end for
} // end main
}
public class BufferedReaderReadLine {
public static void main(String[] args) {
System.out.print("What is your name? ");
// declare the BufferedReader Class
// used the InputStreamReader to read the console input
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
String readVal;
// catch the possible IOException by the readLine() method
try {
// assign the return value of the readLine() method to a variable
readVal = reader.readLine();
// print the text read by the BufferedReader
System.out.println("String read from console input:" + readVal);
// close the BufferedReader object
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public class App {
public static void main(String[] args) {
try {
InputStream inputStream = new FileInputStream("C:\\technicalkeeda\\hello.txt");
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line = null;
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
bufferedReader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class FileExample1 {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
try (BufferedReader br = Files.newBufferedReader(Paths.get("filename.txt"))) {
// read line by line
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append("\n");
}
} catch (IOException e) {
System.err.format("IOException: %s%n", e);
}
System.out.println(sb);
}
}
protected void read(final ProtocolFactory protocols, final Local file) throws AccessDeniedException {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(file.getInputStream(), Charset.forName("UTF-8")));
try {
String l;
while((l = in.readLine()) != null) {
Matcher array = Pattern.compile("\\[(.*?)\\]").matcher(l);
while(array.find()) {
Matcher entries = Pattern.compile("\\{(.*?)\\}").matcher(array.group(1));
while(entries.find()) {
final String entry = entries.group(1);
this.read(protocols, entry);
}
}
}
}
finally {
IOUtils.closeQuietly(in);
}
}
catch(IOException e) {
throw new AccessDeniedException(e.getMessage(), e);
}
}
private void loadDefinition(String def, Color trans) throws SlickException {
BufferedReader reader = new BufferedReader(new InputStreamReader(ResourceLoader.getResourceAsStream(def)));
try {
image = new Image(basePath+reader.readLine(), false, filter, trans);
while (reader.ready()) {
if (reader.readLine() == null) {
break;
}
Section sect = new Section(reader);
sections.put(sect.name, sect);
if (reader.readLine() == null) {
break;
}
}
} catch (Exception e) {
Log.error(e);
throw new SlickException("Failed to process definitions file - invalid format?", e);
}
}
public static void makeMap() {
try {
InputStream is = EtFuturum.class.getResourceAsStream("/assets/OceanMonument.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String s;
while ((s = br.readLine()) != null) {
String[] data = s.split("-");
data[0] = data[0].trim();
data[0] = data[0].substring(1, data[0].length() - 1);
data[1] = data[1].trim();
String[] coords = data[0].split(",");
WorldCoord key = new WorldCoord(Integer.parseInt(coords[0].trim()), Integer.parseInt(coords[1].trim()), Integer.parseInt(coords[2].trim()));
int value = Integer.parseInt(data[1]);
map.put(key, value);
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void obterDadosBD() throws IOException{
try {
FileReader conf = new FileReader("config.txt");
BufferedReader lerArq = new BufferedReader(conf);
ConnectionFactory.DRIVER = lerArq.readLine();
ConnectionFactory.URL = lerArq.readLine();
ConnectionFactory.USER = lerArq.readLine();
ConnectionFactory.PASS = lerArq.readLine();
conf.close();
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(null,"Erro ao abrir o arquivo config.txt");
}
}
private static String getReceive(HttpURLConnection con) throws IOException {
InputStream is = null;
try {
is = con.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is,
defaulEncoding));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null)
sb.append(line);
return sb.toString();
} finally {
if (null != is)
is.close();
}
}