Which two code fragments allow you to write the salary.dat file if it does not exist under "finance\payroll"?

The current working directory is named finance.
Which two code fragments allow you to write the salary.dat file if it does not exist under “finance\payroll”?

The current working directory is named finance.
Which two code fragments allow you to write the salary.dat file if it does not exist under “finance\payroll”?

A.
public static void setFileContent (String[] s) throws IOException {
path p=paths.get(“payroll\\salary.dat”);
File file=p.toAbsolutePath().toFile();
try (BufferWriter br = new BufferWriter (new FileWriter(File))) {
br.write (�experience new features of java�);
}
}

B.
public static void setFileContent (String[] s) throws IOException {
path p=paths.get (“payroll\\salary.dat”);
File file=p.toAbsolutePath(LinkOption.NOFOLLOW_LINKS).toFile();
try (BufferWriter br = new BufferWriter (new FileWriter(File))) {
br.write (�experience new features of java�);
}
}

C.
public static void setFileContent (String[] s) throws IOException {
File file= new file (“payroll\\salary.dat”).getCanonicalFile();
try (BufferWriter br = new BufferWriter (new FileWriter(File))) {
br.write (�experience new features of java�);
}
}

D.
public static void setFileContent (String[] s) throws IOException {
File file= new File (“payroll\\salary.dat”).getCanonicalFile();
try (BufferWriter br = new BufferWriter (new FileWriter(File))) {
br.write (�experience new features of java�);
}
}

E.
public static void setFileContent (String[] s) throws IOException {
File file=new File (“payroll\\salary.dat”).getAbsolutePath();
try (BufferWriter br = new BufferWriter (new FileWriter(File))) {
br.write (�experience new features of java�);
}
}

Explanation:
The problem in this scenario is how to construct a system-dependent filename from the string “payroll\\salary.dat”.
Regarding File-paths:
1- A file can have many relative paths.
2- Canonical paths are absolute paths.
3- An absolute path is not necessarily a canonical path! This holds trueespecially under Unix, which support symbolic
links. Under Windows, anabsolute path is usually a canonical path.

B:The absolute path can include symbolic links. Here we ignore them with NOFOLLOW_LINKS option.
D: The File.getCanonicalFile Method creates a new instance of a File object representing the file located at the absolute path of the current File object. All ‘.’ and ‘..’ references will be resolved.



Leave a Reply 2

Your email address will not be published. Required fields are marked *


zzZZzzzzZZzzz

zzZZzzzzZZzzz

A,D
B is not corect.
toAbsolutePath() has no parameter

jj

jj

what is the difference between C and D?
They look like the same