for this program I am using the FileWriter, however a requirement for my program is to be able to output a file to a user's desktop with the required information. This is where I get stuck. I'm not sure how to obtain that directory automatically so the user doesn't have to input any information. I've already looked at multiple threads regarding this problem but they don't seem to work, unless im doing it incorrectly.
For reference here are the links to the threads:
Create whole path automatically when writing to a new file
Java How to read/write files to/from any user's desktop
Here is the code
public static void SortLast(Student[] mystudent, int line) throws IOException {
int StudentId;
int Grade;
String LastName;
String FirstName;
String Gender;
FileWriter creator = new FileWriter("C:\Users\JmcIntyre1094\Desktop\LastNameSort.txt");
for (int i = 0; i < line; i++) {
StudentId = mystudent[i].StudentId;
Grade = mystudent[i].Grade;
LastName = mystudent[i].LastName;
FirstName = mystudent[i].FirstName;
Gender = mystudent[i].Gender;
creator.write( StudentId + " " + Grade + " " + LastName + " " + FirstName + " " + Gender);
creator.write(System.getProperty("line.separator"));
}//printing out the lines in the new file
creator.close();
}//Creating the file
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…