J
J
Jake Taylor2021-04-21 16:22:32
Java
Jake Taylor, 2021-04-21 16:22:32

How to correctly compose the path to the file?

There is such a project structure:
608025635e383462550022.jpeg

Task:
- in FileAppender you need to specify the path to the file to which the logs will be written.

What I did:
Registered a path like this:

log/$${date:dd:MM:yyyy}/log-$${date:dd:MM:yyyy-HH:mm}.txt


But IntellijIDEA throws an exception:
ERROR FileManager (log/21:04:2021/log-21:04:2021_15:58.txt) java.io.IOException: The filename, directory name, or volume label syntax is incorrect


The official Log4J 2 documentation says that
fileName String The name of the file to write to. If the file, or any of its parent directories, do not exist, they will be created.
which means if the file does not exist in the given path, it will be created. By what rules then the way is set?

Question:
What is wrong in my path to the file where the logs will be written?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Alexandrov, 2021-04-21
@n199a

java.io.IOException: The filename, directory name, or volume label syntax is incorrect

file name, directory name, or volume name is incorrect.
The official Log4J 2 documentation says that
fileName String The name of the file to write to. If the file, or any of its parent directories, do not exist, they will be created.
which means if the file does not exist in the given path, it will be created. By what rules then the way is set?

Great, but there are still limitations on the names of the OS itself and / or the file system in it.
In Windows, this is \/:*?<>"|
There are also restrictions in the words themselves and you will find them at the link above.
In general, this is not a problem of java itself, and not a problem at all, these are limitations of the FS and OS.

D
Denis Zagaevsky, 2021-04-21
@zagayevskiy

I guess you need to write ./log/...

D
Deiwan, 2021-04-21
@Deiwan

If in one package, then import is not needed, and if not in one, then through import package.directory.file or * to import everything, and if in another place, then the full path like DISK:\general_package\package\directory\file to import

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question