Saving the full path
To save to a database you must save the path as a String
.
Obviously your code that reads and writes the records can encapsulate this String in a File
, for example, retrieving the String
bank and creating a File
or retrieving the file path as String
and writing to database.
In this situation, do whatever is most convenient.
Organizing the files
However, unless it is an absolutely necessary requirement of your system, I would not save the full path of the files.
In general, it would be more appropriate to define a directory in the program configuration and save all selected files in that directory.
Then you can save only the names of images in the database, and when you need to save the file, just do something like:
new File(configuracao.getPastaArquivos(), nomeArquivo)
Incidentally, neither is the filename required. If you have, for example, a table in the database where you save the file information, you can simply save the file in the folder using the ID as the name.
So the path on the disk would look something like this:
new File(configuracao.getPastaArquivos(), arquivo.getId())
In this way, the data in the file (such as your name) stays in the database and you have everything organized into a folder by the ID.
Easier to back up, move files to another location if needed, and also avoid problems with special characters in names, spaces, and accents. It also allows situations where two system users send a file with the same name.