Rename file from outside when it's opened in Java

JetStream

I'm coding a Java Application right now and it has to read through a file. I'm using this method to do so:

BufferedReader mb_reader = new BufferedReader(new FileReader(f1));
int lines = 0;
while (null != (mb_line = mb_reader.readLine())) {
    lines++;
    //something to do
}

Everything works fine but it's possible that the file has to be changed from outside (for example).

I have a mthod that tests if the file exists and then open this reader. But if I now try to rename the file in the Windows Explorer it just says that the file is opened in Java and can not be renamed.

Is there a way to make it possible to rename it even if it's opened?

Laurentiu L.

You need to close the stream to release the file to the system, i don't think there's a straightforward way around this.

You could have a working copy to read from and check the file every now and then for changes you might expect.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Keep batch file from waiting for completion of opened file[s]?

From Dev

Keep batch file from waiting for completion of opened file[s]?

From Dev

HTML not working when opened from file, works from ftp server

From Dev

Outside Bounds of Array When Reading From File

From Dev

Hide opened drawer when clicking outside of the drawer

From Dev

How to invoke a plugin in vim when no file is opened from commandline?

From Dev

Onfileloaded event not called when file is opened from Drive

From Dev

Exported excel file from datagridview shows error when opened VB

From Dev

Onfileloaded event not called when file is opened from Drive

From Dev

file is not removed when rename

From Dev

How to rename file java ?

From Dev

Python - How to know if a file is completed when copying from an outside process

From Dev

Access joomla's helpers from outside php file

From Dev

Where does the localhost port number come from when a file is opened in the browser from Visual Studio?

From Dev

Rename file when upload in php

From Dev

rename file from php form

From Dev

How to eliminate new line character from text file when opened in python?

From Dev

java - File length after rename

From Dev

How can I send a html file from the server to be opened in the client's browser?

From Dev

Eclipse/LiClipse freezes when .py file is opened

From Dev

There is no such file when picture opened with Image.show()

From Dev

Refreshing chart when a new file is opened

From Dev

File is not created/opened when using with open

From Dev

How to track opened file(s) in Android Studio?

From Dev

In Java, how do you obtain a Socket or DatagramSocket from the file descriptor of an already opened C socket?

From Dev

Lock page when it's already opened

From Dev

Error in fsproj file prevents it from being opened

From Dev

Setting multiple variables from opened file - Python

From Dev

Scope of variable from a file opened in Bash

Related Related

  1. 1

    Keep batch file from waiting for completion of opened file[s]?

  2. 2

    Keep batch file from waiting for completion of opened file[s]?

  3. 3

    HTML not working when opened from file, works from ftp server

  4. 4

    Outside Bounds of Array When Reading From File

  5. 5

    Hide opened drawer when clicking outside of the drawer

  6. 6

    How to invoke a plugin in vim when no file is opened from commandline?

  7. 7

    Onfileloaded event not called when file is opened from Drive

  8. 8

    Exported excel file from datagridview shows error when opened VB

  9. 9

    Onfileloaded event not called when file is opened from Drive

  10. 10

    file is not removed when rename

  11. 11

    How to rename file java ?

  12. 12

    Python - How to know if a file is completed when copying from an outside process

  13. 13

    Access joomla's helpers from outside php file

  14. 14

    Where does the localhost port number come from when a file is opened in the browser from Visual Studio?

  15. 15

    Rename file when upload in php

  16. 16

    rename file from php form

  17. 17

    How to eliminate new line character from text file when opened in python?

  18. 18

    java - File length after rename

  19. 19

    How can I send a html file from the server to be opened in the client's browser?

  20. 20

    Eclipse/LiClipse freezes when .py file is opened

  21. 21

    There is no such file when picture opened with Image.show()

  22. 22

    Refreshing chart when a new file is opened

  23. 23

    File is not created/opened when using with open

  24. 24

    How to track opened file(s) in Android Studio?

  25. 25

    In Java, how do you obtain a Socket or DatagramSocket from the file descriptor of an already opened C socket?

  26. 26

    Lock page when it's already opened

  27. 27

    Error in fsproj file prevents it from being opened

  28. 28

    Setting multiple variables from opened file - Python

  29. 29

    Scope of variable from a file opened in Bash

HotTag

Archive