Skip to content

Instantly share code, notes, and snippets.

@ayoolaao
Created February 16, 2018 17:44
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 ayoolaao/d9e62805ede79b71c9e000e1b575cf54 to your computer and use it in GitHub Desktop.
Save ayoolaao/d9e62805ede79b71c9e000e1b575cf54 to your computer and use it in GitHub Desktop.
lambda exp
package com.java.io;
import java.io.IOException;
import java.nio.file.*;
public class JavaIO {
static String dir = "./";
static String text = "./UX_resume_nlb.txt";
public static void main(String[] args){
//TODO
try {
// walkDirectory(dir);
// deleteFile(dir);
System.out.println(readFile(text).toString());
} catch (Exception e){
e.printStackTrace();
}
}
public static void walkDirectory(String path) throws IOException{
Files.walk(Paths.get(path)).forEach(f -> System.out.println(f.toFile()));
}
public static void deleteFile(String path) throws IOException{
Files.delete(Paths.get(path));
}
public static StringBuffer readFile(String path) throws IOException{
StringBuffer content = new StringBuffer();
// Files.lines(Paths.get(path)).forEach(l -> System.out.println(l));
// Files.lines(Paths.get(path)).forEach(System.out::println);
Files.lines(Paths.get(path)).forEach(l -> content.append(l).append("\n"));
// Files.lines(Paths.get(path)).forEach(l -> content.append(l));
// Files.lines(Paths.get(path)).forEach(content::append);
return content;
}
}
@abimbolaof
Copy link

Makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment