Java Reference
In-Depth Information
and use different directory separator characters. If you need to work with a file
or directory, have the user specify the filename, or at least the base directory
beneath which the file can be found. This specification can be done at runtime,
in a configuration file, or as a command-line argument to the program. When
concatenating a file or directory name to a directory name, use the
File()
con‐
structor or the
File.separator
constant.
Line separators
Different systems use different characters or sequences of characters as line
separators. Do not hardcode
\n
,
\r
, or
\r\n
as the line separator in your pro‐
gram. Instead, use the
println()
method of
PrintStream
or
PrintWriter
,
which automatically terminates a line with the line separator appropriate for
the platform, or use the value of the
line.separator
system property. You can
also use the “%n” format string to
printf()
and
format()
methods of
java.util.Formatter
and related classes.
s