Java File create new file in user home directory

Description

Java File create new file in user home directory

//   Licensed under the Apache License, Version 2.0 (the "License");

//package com.demo2s;

import java.io.File;

public class Main {
    public static void main(String[] argv) throws Exception {
        String name = "";
        System.out.println(atHomeDir(name));
    }/*from ww w .ja v  a  2  s  .  c  om*/

    /**
     * Creates a new {@link File} prepending the user home directory to the
     * informed filename.
     * 
     * @param name
     *            the filename to be located at the user home directory.
     * @return the {@link File} object. Note that the file existence must be
     *         checked using {@link File#exists()}.
     */
    public static File atHomeDir(String name) {
        File f = new File(System.getProperty("user.home").concat(System.getProperty("file.separator")).concat(name));
        return f;
    }
}



PreviousNext

Related