Path file = ...; InputStream in = null; try { in = file.newInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = null; while ((line = reader.readLine()) != null) { System.out.println(line); } } catch (IOException x) { System.err.println(x); } finally { if (in != null) in.close(); }
crire dans le fichier temporaire les lignes ne commençant pas par "E".
import java.io.*; class FileRead { public static void main(String args[]) { try{ // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("c://Source/file.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; String str1 = "E"; while ((strLine = br.readLine()) != null && strLine.startsWith(str1)) { ? } //Close the input stream in.close(); } catch (Exception e) {//Catch exception if any System.err.println("Error: " + e.getMessage()); } } }