You may use \\
or you may use a /
. I suggest you use the latter as it is platform independent.
Also, use the constructor:
File(String parent, String child)
The docs say:
Creates a new File instance from a parent pathname string and a child
pathname string. If parent is null then the new File instance is
created as if by invoking the single-argument File constructor on the
given child pathname string.
Otherwise the parent pathname string is taken to denote a directory,
and the child pathname string is taken to denote either a directory or
a file. If the child pathname string is absolute then it is converted
into a relative pathname in a system-dependent way. If parent is the
empty string then the new File instance is created by converting child
into an abstract pathname and resolving the result against a
system-dependent default directory. Otherwise each pathname string is
converted into an abstract pathname and the child abstract pathname is
resolved against the parent.
So, your code should look like:
fichero = new File(fichero.getAbsolutePath(),str);
NB: You may also use the File
constructor that accepts a File
and String
as an argument, thus eliminating the call to getAbsolutePath()