Active 5 years, 7 months ago. Viewed 42k times. Improve this question. Giannis Giannis 4, 13 13 gold badges 50 50 silver badges bronze badges. This is from the Java documentation "Whether or not this method can move a file from one filesystem to another is platform-dependent. The return value should always be checked to make sure that the rename operation was successful.
Yes its always returning false. The only time it worked is when I set the new File name manually but without including the path : "test. That created a txt containing "test one" but not at the selected directory — Giannis. Are you sure the target file doesn't already exist? A new file is created but without extension. I just do the test on desktop so I can see whats happening. Show 1 more comment. Active Oldest Votes. Improve this answer. Luke Woodward Luke Woodward Yes you are right I ended up just creating a new File using the name directory from the Chooser.
I just thought the renameTo was an operation that could be used in this case. In my case, the BufferedReader was open. For this reason the file can't be renamed. Add a comment. From the docs: Moves the file from one path to another. Andrejs Andrejs It may be that in the next patchlevel of a given JDK, a call that used to fail will now succeed.
It also may be that whether a given call will work or not depends on the physical OS you're running on top of, the filesystems in use, etc. In general, expect renameTo to work within a given directory. Outside of that, anticipate that it may not. I realise that it returns a boolean. That's why I test for it. Jack, there is no exception. The boolean is just set to false. On windows I can renameTo across partitions, but on Linux I can't.
The function returns true if the file is renamed else returns false Function Signature: public boolean renameTo File destination Syntax: file. Return Value: The function returns boolean data type. The function returns true the file is renamed else returns false. Skip to content.
Change Language. Related Articles. Table of Contents. Improve Article. Save Article.
0コメント