Get file name from FileOutputStream

后端 未结 5 1055
别那么骄傲
别那么骄傲 2020-11-29 09:52

Is there a way to get the file name from a FileOutputStream or from FileInputStream?

5条回答
  •  春和景丽
    2020-11-29 10:20

    My answer comes a little late. I hit the same issue when writing some code.

    To get around it, I used a FileOutputStream(File file) instead of FileOutputStream(String location) because I can then do file.getAbsolutePath(). See the example snippet below.

    String location = "some.relative.path.txt";
    File file = new File(location);
    FileOutputStream f = new FileOutputStream(file);
    String question = "

    "+header+"

    "; String finalSource = HTMLWrapper.HTML_START+question +htmlContent; f.write(finalSource.getBytes()); f.flush(); f.close(); System.out.println("The report is now available at"+file.getAbsolutePath());

提交回复
热议问题