I'm creating a program to create and write to a file for homework, but it just won't compile. Everything looks okay, so I don't understand what's happening.
import java.nio.file.*; import java.io.*; import java.nio.channels.FileChannel; import java.nio.ByteBuffer; import static java.nio.file.StandardOpenOption.*; import java.util.Scanner; import java.text.*; public class WritePhoneList { public static void main(String[] args) { Scanner input = new Scanner(System.in); Path phoneList = Paths.get("C:\\Users\\Rayne\\Documents\\School Work\\CIST 2372\\PhoneList.txt"); String delimiter = ","; String s = "000-000-000,FFFFFFFFFFF,LLLLLLLLLL" + System.getProperty("line.separator"); final int RECSIZE = s.length(); FileChannel fc = null; String phoneNumber; String firstName; String lastName; final String QUIT = "999"; createEmptyFile(phoneList, s); try { fc = (FileChannel)phoneList.newByteChannel (CREATE, WRITE); System.out.print("Enter phone number in 000-000-000 format or " + QUIT + " to quit >> "); phoneNumber = input.nextLine(); while(!(phoneNumber.equals(QUIT))) { System.out.print("Enter first name for phone number " + phoneNumber + " >> "); firstName = input.nextLine(); System.out.print("Enter last name >> "); lastName = input.nextLine(); s = phoneNumber + delimiter + firstName + delimiter + lastName + System.getProperty("line.separator"); byte[] data = s.getBytes(); ByteBuffer buffer = ByteBuffer.wrap(data); fc.write(buffer); System.out.print("Enter next phone number or " + QUIT + " to quit >> "); phoneNumber = input.nextLine(); } fc.close(); } catch (Exception e) { System.out.println("Error message: " + e); } } public static void createEmptyFile(Path file, String s) { final int NUMRECS = 100; try { OutputStream outputStr = new BufferedOutputStream(file.newOutputStream(CREATE)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStr)); for(int count = 0; count < NUMRECS; ++count) writer.write(s, 0, s.length()); writer.close(); } catch (Exception e) { System.out.println("Error message: " + e); } } }
The error messages I get are:
error: cannot find symbol
symbol: method newByteChannel (StandardOpenOption, StandardOpenOption)
location: variable phoneList of type Path
error: cannot find symbol
symbol: method newOutputStream (StandardOpenOption)
location: variable file of type Path