try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line;
while ((line = br.readLine()) != null) {
// process the line.
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public static void readText throws FileNotFoundException {
Scanner scan = new Scanner(new File("samplefilename.txt"));
while(scan.hasNextLine()){
String line = scan.nextLine();
//Here you can manipulate the string the way you want
}
}
try( BufferedReader reader = new BufferedReader( ... ) ) {
reader.lines().foreach( line -> processLine( line ) );
}
String pathFile="/path/to/file.txt";
String cmd="type";
if(System.getProperty("os.name")=="Linux"){
cmd="cat";
}
Process p= Runtime.getRuntime().exec(cmd+" "+pathFile);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
System.out.println(p.getOutputStream().toString());
String s = null;
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
No comments:
Post a Comment