小编sur*_*uru的帖子

是否可以在java中关闭源文件(file.close();)?

我正在创建一个新文件

File f = new File(file_path);
Run Code Online (Sandbox Code Playgroud)

然后程序结束我可以关闭文件对象或文件?

f.close();
Run Code Online (Sandbox Code Playgroud)

否则有一种方法可以关闭文件??

     public class etest2read {
     public static void main(String[] args) throws IOException {
    File dir = new File("input");

    String source = dir.getCanonicalPath() + File.separator + "TestFile.txt";
    //String TestFileone = dir.getCanonicalPath() + File.separator + "TestFileone.txt";

    File fin = new File(source);
    FileInputStream fis = new FileInputStream(fin);
    BufferedReader br = new BufferedReader(new InputStreamReader(fis));

    System.out.println("file/folder: "+fin.getAbsolutePath());
    System.out.println("file/folder: "+dir.getCanonicalPath());
    System.out.println("file/folder: "+fin.lastModified());


    String strLine;

     //Read File Line By Line
    while ((strLine = br.readLine()) != null)   {
   // Print …
Run Code Online (Sandbox Code Playgroud)

java notepad file

0
推荐指数
1
解决办法
883
查看次数

标签 统计

file ×1

java ×1

notepad ×1