Skip to content

Instantly share code, notes, and snippets.

@ayoolaao

ayoolaao/JavaIO.java

Created Feb 16, 2018
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@abimbolaof abimbolaof commented Feb 16, 2018

Makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.