import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.Arrays;
import java.util.LinkedList;
public class ProjectTwoAccessControl{
// public static void fOrAAdd(String x,PrintWriter n){
// n.write(x);
// }
public static void main(String [] args) throws IOException{
PrintWriter friends = new PrintWriter("friends.txt");
PrintWriter audit = new PrintWriter("auditlog.txt");
try {
FileInputStream inputCommands;
inputCommands = new FileInputStream("test.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(inputCommands));
String line;
while ((line = br.readLine()) != null){ //2
String[] command = line.split(" ");
System.out.println(Arrays.toString(command));
// for(int i = 0; i < command.length;i++){ //1
if (command[0] == "friendadd"){
friends.write(command[1]);
audit.write("Friend " + command[1] + " was added.");
}
// } //1
} //2
}//try end
catch (FileNotFoundException e) {
System.out.println("No file found by this name");
}
friends.close();
audit.close();
}
}
I am attempting to make a social media style of access control for a school assignment, and am going to continue working on this all evening, but I cannot figure out why the PrintWriters are not writing. I added in to print the array "command" out, and it seems to be working correctly, but nothing will print to my friends.txt or audit.txt.