Read file with whitespace in its path using Java

后端 未结 4 825
春和景丽
春和景丽 2020-12-03 18:42

I am trying to open files with FileInputStream that have whitespaces in their names.

For example:

String fileName = \"This is my file.txt\";
String          


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 18:48

    File name with space works just fine

    Here is my code

    File f = new File("/Windows/F/Programming/Projects/NetBeans/TestApplications/database prop.properties");
            System.out.println(f.exists());
            try
            {
                FileInputStream stream = new FileInputStream(f);
            }
            catch (FileNotFoundException ex)
            {
                System.out.println(ex.getMessage());
            }
    

    f.exists() returns true always without any problem

提交回复
热议问题