Skip to content

Instantly share code, notes, and snippets.

@diabloneo
Created October 22, 2014 15:32
Show Gist options
  • Select an option

  • Save diabloneo/705521c6529206c3111b to your computer and use it in GitHub Desktop.

Select an option

Save diabloneo/705521c6529206c3111b to your computer and use it in GitHub Desktop.
Process home directory in Java.
/**
* Created by diabloneo on 10/1/14.
*/
import java.io.IOException;
import java.util.Scanner;
import java.nio.file.Paths;
public class Hello {
public static void main(String[] args) {
String wordFile = "~/tmp/words";
try {
Scanner in = new Scanner(Paths.get(wordFile.replace("~", System.getProperty("user.home"))));
while (in.hasNext()) {
System.out.println(in.nextLine());
}
} catch (IOException e) {
System.out.println(e);
System.exit(1);
}
}
}
@diabloneo

Copy link
Copy Markdown
Author

Of course, you should consider about security problem.

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