Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public File createFileInDirectory(String directoryPath){
- File file = new File(directoryPath);
- if(file.getParentFile().mkdirs()){
- try {
- file.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- return null;
- }
- return file;
- }
- return null;
- }
- public void readAndPrintFromFile(File file){
- try {
- Scanner sc=new Scanner(file);
- while(sc.hasNextLine()){
- System.out.println(sc.nextLine());
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- Main main = new Main();
- main.readAndPrintFromFile(main.createFileInDirectory("C:"+File.separator+"Windows"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement