I am thoroughly confused by "bufferedWriter" and "FileWrit

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 519 Views - Last Post: 01 July 2013 - 08:51 PM Rate Topic: -----

#1 Dylsauce  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 98
  • Joined: 30-June 13

I am thoroughly confused by "bufferedWriter" and "FileWrit

Posted 01 July 2013 - 12:02 PM

I am making a social network for class, the network needs to be able to read and write files to and from the disk. We have been given two classes that are supposed to help us but they use complicated methods that I cannot after hours of searching understand. Can someone please break it down for me so I can undertand? Here are the methods we are give:
import java.io.*;

/**
 * OutStringFile makes file writing simpler. It allows
 * information to be written one line at a time to a
 * data file, as a String.
 * @author CS1027
 */
public class OutStringFile {
   
    /**
     * the handle to write to the file
     */
    private BufferedWriter out;
    
	 /**
     * Constructs the object that controls file writing
     * Exits gracefully if unable to write to file
     * @param filename the name of the file to be written to
     */
    public OutStringFile(String filename) {   
        try {   	
          out = new BufferedWriter(new FileWriter(filename));
        }
        catch (IOException e){
           System.out.println("File " + filename + " cannot be written.");
           System.exit(0);
	  }
    }

    /**
     * Writes a line of output as a String
     * Exits gracefully if an error occurs while writing the file
     * @param the line to be written
     */ 
    public void write(String line) {
      try {
    	  out.write(line);
      }
      catch (IOException e){
         System.out.println("File cannot be written.");
         System.exit(0);
      }
	}

    /**
     * Closes the file (making it inaccessible though this OutStringFile)
     */
    public void close(){
       try {
          out.close();
          out = null;
       }
       catch (IOException e){
           System.out.println("Problem closing file.");
           System.exit(0);
       }
    }
}




and

import java.io.*;

/**
 * InStringFile makes file reading simpler. It allows
 * information to be read one line at a time from a
 * data file, as a String.
 * @author CS1027
 */
public class InStringFile {
   
    /**
     * the handle to read in the file
     */
    private BufferedReader in;
    /**
      * the next line of the file to be read
      */
    private String nextLine;


    /**
     * Constructs the object that controls file reading
     * Exits gracefully if file not found or file cannot be read
     * @param filename the name of the file to be read
     */
    public InStringFile(String filename) {   
        try {   	
	    in = new BufferedReader(new FileReader(filename));
          nextLine = in.readLine();
        }
        catch (FileNotFoundException ee){
           System.out.println("File " + filename + " not found.");
           System.exit(0);
        }
        catch (IOException e){
           System.out.println("File " + filename + " cannot be read.");
           System.exit(0);
	  }
    }

    /**
     * Reads the next line of input as a String
     * Exits gracefully if an error occurs while reading the file
     * @return the next line from the input file
     */ 
    public String read() {
      String current = nextLine;
	  try {
	   nextLine = in.readLine();
      }
      catch (IOException e){
         System.out.println("File cannot be read.");
         System.exit(0);
      }
	  return current;
    }

    /**
     * Lookahead test for end of input
     * @return true if end of file has been reached
     */
    public boolean endOfFile() {
        return (nextLine == null);
    }

    /**
     * Closes the file (making it inaccessible though this InStringFile)
     */
    public void close(){
       try {
          in.close();
          in = null;
       }
       catch (IOException e){
           System.out.println("Problem closing file.");
           System.exit(0);
       }
    }
}


and then here is what I have for my read and write methods:

public void readList(String fileName) throws Exception {

		// create object that controls file reading and opens the file

		InStringFile reader = new InStringFile(fileName);
		System.out.println("\nReading from file " + fileName + "\n");

		// read data from file one line at a time

		String line;
		StringTokenizer tokenizer;
		String firstName, lastName, email;
		int year, month, day;
		do {
			line = (reader.read());

			// get person info from line read in from file, one at a time,
			// Note: it is assumed that each line of the disk file will have
			// all 6 items, separated by white space

			tokenizer = new StringTokenizer(line);
			firstName = tokenizer.nextToken();
			lastName = tokenizer.nextToken();
			email = tokenizer.nextToken();
			year = Integer.parseInt(tokenizer.nextToken());
			month = Integer.parseInt(tokenizer.nextToken());
			day = Integer.parseInt(tokenizer.nextToken());
			String noData = "?";

			// adds the new person
			Person friend = new Person(firstName, lastName, email, year, month,
					day);

			// add it to the array of friends
			// if array is not big enough, double its capacity automatically
			if (numFriends == friendList.length)
				expandCapacity();

			/*
			 * if(email.equals(noData)) line = null;
			 * 
			 * if(year == 0) line = null;
			 */

			// add reference to friend at first free spot in array
			friendList[numFriends] = friend;
			numFriends++;

		}

		while (line != null);

	}


	// write list method, writes a list
	public void writeList(String fileName) {
		
	}


like private BufferedWriter out ?? what kind of construction is that...?

Is This A Good Question/Topic? 0
  • +

Replies To: I am thoroughly confused by "bufferedWriter" and "FileWrit

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10646
  • View blog
  • Posts: 39,536
  • Joined: 27-December 08

Re: I am thoroughly confused by "bufferedWriter" and "FileWrit

Posted 01 July 2013 - 12:07 PM

To write to a File, you would just use the OutStringFile write() method on your OutStringFile object. Note you would probably want to store an OutStringFile object as an instance variable.
class Test{

    private OutStringFile writer;

    public Test(){
       writer = new OutStringFile("myfile.txt");
    }

    public void writeLine(String line){
       writer.write(line);
    }
}



It works similarly as with your InStringFile class.
Was This Post Helpful? 0
  • +
  • -

#3 Dylsauce  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 98
  • Joined: 30-June 13

Re: I am thoroughly confused by "bufferedWriter" and "FileWrit

Posted 01 July 2013 - 01:55 PM

thanks, but when I try to use my readList method, i get this error and I dont know what a tokenizer is so I dont know how to fix it:
Exception in thread "main" java.util.NoSuchElementException
	at java.util.StringTokenizer.nextToken(StringTokenizer.java:332)
	at SocialNetwork.readList(SocialNetwork.java:64)
	at TestSocialNetwork.main(TestSocialNetwork.java:18)

Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10646
  • View blog
  • Posts: 39,536
  • Joined: 27-December 08

Re: I am thoroughly confused by "bufferedWriter" and "FileWrit

Posted 01 July 2013 - 02:26 PM

That Exception means that there is no element to read. Either you've read all the tokens or there are no more tokens.

Quote

I dont know what a tokenizer is so I dont know how to fix it:

This is a good time to start learning how to use the docs. They're going to be your best friends regardless of language. Googling StringTokenizer 7 came up with the docs here.

Taken straight from the StringTokenizer page:

Quote

StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.

Was This Post Helpful? 0
  • +
  • -

#5 Dylsauce  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 98
  • Joined: 30-June 13

Re: I am thoroughly confused by "bufferedWriter" and "FileWrit

Posted 01 July 2013 - 04:39 PM

I thought I had fixed it but now I'm getting
Exception in thread "main" java.lang.RuntimeException: Invalid date
	at Date.<init>(Date.java:18)
	at Person.<init>(Person.java:47)
	at SocialNetwork.readList(SocialNetwork.java:71)
	at TestSocialNetwork.main(TestSocialNetwork.java:22)


and I created my own date class but the Date.java:18 links to java.date.util !! aah I have been working on this for like 8 hours . . i don't know what to do, I've tried creating a new project and putting the code back in, closing Eclipse and rebooting it, I've scoured my code and I dont see anything that could be causing this! I even tried to find someone to help but he wants $65! im lost.
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10646
  • View blog
  • Posts: 39,536
  • Joined: 27-December 08

Re: I am thoroughly confused by "bufferedWriter" and "FileWrit

Posted 01 July 2013 - 04:46 PM

Post your revised code.
Was This Post Helpful? 0
  • +
  • -

#7 Dylsauce  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 98
  • Joined: 30-June 13

Re: I am thoroughly confused by "bufferedWriter" and "FileWrit

Posted 01 July 2013 - 04:52 PM

Okay so here is everything I've got:
This is the main im trying to actually run, everything else is just classes needed to do so

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Test program to show that your Assignment 1 classes work as specified
 * 
 * @author CS1027 for Asn1
 */
public class TestSocialNetwork {

	public static void main(String[] args) throws Exception {

		SocialNetwork contacts = new SocialNetwork();

		// get the filename to read from, from the user
		BufferedReader keyboard = new BufferedReader(new InputStreamReader(
				System.in), 1);
		System.out.println("Enter name of the file to read from: ");
		String fileName = keyboard.readLine();

		// add friends from the file
		contacts.readList(fileName);
		System.out.println(contacts.toString());
		System.out.println("I have " + contacts.getNumFriends()
				+ " friends in my contact list.");

		// MY CODE
		// adds a person to the network
		contacts.add("Jebediah", "Springfield", "jibjab@awesomesauce.ca", 1774,
				12, 1);

		// Display the updated list
		System.out.println(contacts);

		// Search for a friend and update his/her email address and birthday
		Person jebediah = new Person("Jebediah", "Springfield",
				"jibjab@awesomesauce.ca", 1774, 12, 1);
		Person found = contacts.findFriend(jebediah);
		found.setBirthday(1774, 12, 2);
		found.setEmail("hungry4rock@tepidmail.ca");

		// Display the updated list
		System.out.println(contacts);

		// Search for a friend and display his/her email and birthday
		Person target = contacts.findFriend(jebediah);
		System.out.println(target.getEmail());
		System.out.println(target.getBirthday());

		// Search for a friend who is not in the list, and display an
		// appropriate error message
		contacts.findFriend(new Person("mustachio", "banderas", "mbanderas",
				1960, 8, 10));

		// get a disk location as input from user
		BufferedReader typer = new BufferedReader(new InputStreamReader(
				System.in), 1);
		System.out
				.println("Enter location where you would like your file saved: ");
		String location = typer.readLine();

		// write the file to that location
		contacts.writeList(location);

	}

}



Person class

/**
 * Class that represents a person with attributes name, email address
 * 
 * @author CS1027
 * 
 */
public class Person {

	/* Attribute declarations */
	private String lastName; // last name
	private String firstName; // first name
	private String email; // email address
	private Date birthday; // birthday

	/**
	 * Constructor initializes the person's name, email address, and birthday
	 * using the empty constructor
	 * 
	 * @param firstName
	 * @param lastName
	 * @param email
	 */
	public Person(String firstName, String lastName, String email) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
		this.birthday = new Date();
	}

	/**
	 * Constructor initializes the person's name, email address and birthday
	 * with year month and day passed as parameters
	 * 
	 * @param firstName
	 * @param lastName
	 * @param email
	 * @param year
	 * @param month
	 * @param day
	 * @author Dylan Harness
	 */
	public Person(String firstName, String lastName, String email, int year,
			int month, int day) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
		this.birthday = new Date(year, month, day);
	}

	// //////////////////////////Methods////////////////////////////

	/**
	 * getName method returns the person's full name
	 * 
	 * @return first name followed by last name, blank separated
	 */
	public String getName() {
		return firstName + " " + lastName;
	}

	/**
	 * getEmail method returns the person's email address
	 * 
	 * @return email address
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * setEmail method sets the person's email address
	 * 
	 * @param email
	 */

	public Date getBirthday() {
		return birthday;
	}

	/**
	 * Sets the first and last name of a person with the new names passed as
	 * paramaeters
	 * 
	 * @param firstName
	 * @param lastName
	 * @author Dylan Harness
	 */

	public void setName(String firstName, String lastName) {
		this.firstName = firstName;
		this.lastName = lastName;
	}

	/**
	 * sets the email of the person passed in as a parameter
	 * 
	 * @param email
	 */

	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * sets the birthday of the person with the year month and day of the dat
	 * passed as parameters
	 * 
	 * @param year
	 * @param month
	 * @param day
	 */
	public void setBirthday(int year, int month, int day) {
		this.birthday = new Date(year, month, day);
	}

	/**
	 * equals method determines whether two persons have the same name
	 * 
	 * @param other
	 *            other Person object that this is compared to
	 * @return true of they have the same first name and last name, false
	 *         otherwise
	 */
	public boolean equals(Person other) {
		if (this.firstName.equals(other.firstName)
				&& this.lastName.equals(other.lastName))
			return true;
		else
			return false;
	}

	/**
	 * toString method returns a string representation of the person
	 * 
	 * @return string with first name and last name, email address
	 */
	public String toString() {
		if (birthday.getYear() == 0) {
			String s = firstName + " " + lastName + "\t" + email;
			return s;
		} else {
			String s = (firstName + " " + lastName + "\t" + email + " " + birthday
					.toString());
			return s;

		}

	}

	/*
	 * test harness to test all the methods of the person class // public static
	 * void main(String[] args) {
	 * 
	 * Person heather = new Person("Heather", "Booker",
	 * "heather.booker@hotmail.com", 1993, 10, 20); Person dylan = new
	 * Person("Dylan", "Harness", "dylsauce@hotmail.com");
	 * 
	 * System.out.println(dylan.getName());
	 * System.out.println(dylan.getEmail());
	 * System.out.println(dylan.getBirthday()); System.out.println(dylan);
	 * System.out.println(heather.getName());
	 * System.out.println(heather.getEmail());
	 * System.out.println(heather.getBirthday()); System.out.println(heather);
	 * 
	 * dylan.setName("Captain", "Newman");
	 * dylan.setEmail("CapNewman@awesomesauce.com"); dylan.setBirthday(1991, 2,
	 * 6); System.out.println(dylan.getName());
	 * System.out.println(dylan.getEmail());
	 * System.out.println(dylan.getBirthday()); System.out.println(dylan);
	 * 
	 * 
	 * }
	 */
}


My Date class:

/**
 * A class that represents a date as having a year, month, and day
 * 
 * @author Dylan Harness
 * 
 */

public class Date {

	/* Attribute declarations */
	private int year;
	private int month;
	private int day;

	/**
	 * Constructor without any parameters. Sets all attributes to zero
	 */
	public Date() {
		year = 0;
		month = 0;
		day = 0;
	}

	/**
	 * Constructor which initializes the year, month, and day of a date as
	 * integer values
	 * 
	 * @param year
	 * @param month
	 * @param day
	 */
	public Date(int year, int month, int day) {
		this.year = year;
		this.month = month;
		this.day = day;
	}

	// //////////////////////////Methods////////////////////////////
	/*
	 * A series of getter methods that return the year month and day of the date
	 * as integer values
	 */

	/**
	 * 
	 * @return the year of a date
	 */
	public int getYear() {
		return year;
	}

	/**
	 * 
	 * @return the month of a date
	 */
	public int getMonth() {
		return month;
	}

	/**
	 * 
	 * @return the calendar day of a date
	 */
	public int getDay() {
		return day;
	}

	/**
	 * sets the year as an integer value
	 * 
	 * @param year
	 */
	public void setYear(int year) {
		// if(year>0){
		this.year = year;
		// }
	}

	/**
	 * sets the month as an integer value
	 * 
	 * @param month
	 */
	public void setMonth(int month) {
		// if(month>=0){
		this.month = month;
		// }
	}

	/**
	 * sets the day as an integer value
	 * 
	 * @param day
	 */
	public void setDay(int day) {
		// if(day>=0){
		this.day = day;
		// }
	}

	/* toString which returns the year month and day with spaces in between */
	public String toString() {
		return (year + " " + month + " " + day);
	}
}


The social network itself:

import java.util.*;

/**
 * Class that represents a social network as a list of persons (friends or
 * contacts)
 * 
 * @author CS1027
 */
public class SocialNetwork {

	private final int DEFAULT_MAX_FRIENDS = 10; // default size of array

	/* Attribute declarations */
	private Person[] friendList; // array of persons (list of friends)
	private int numFriends; // current number of persons in list

	/**
	 * Constructor creates person array of default size
	 */
	public SocialNetwork() {
		friendList = new Person[DEFAULT_MAX_FRIENDS];
		numFriends = 0;
	}

	/**
	 * Constructor creates person array of specified size
	 * 
	 * @param max
	 *            maximum size of array
	 */
	public SocialNetwork(int max) {
		friendList = new Person[max];
		numFriends = 0;
	}

	/**
	 * readList method adds into the social network list from a file
	 * 
	 * @param fileName
	 *            filename of file that contains friend information
	 */
	public void readList(String fileName) throws Exception {

		// create object that controls file reading and opens the file

		InStringFile reader = new InStringFile(fileName);
		System.out.println("\nReading from file " + fileName + "\n");

		// read data from file one line at a time

		String line;
		StringTokenizer tokenizer;
		String firstName, lastName, email;
		int year, month, day;
		do {
			line = (reader.read());

			// get person info from line read in from file, one at a time,
			// Note: it is assumed that each line of the disk file will have
			// all 6 items, separated by white space

			tokenizer = new StringTokenizer(line);
			firstName = tokenizer.nextToken();
			lastName = tokenizer.nextToken();
			email = tokenizer.nextToken();
			year = Integer.parseInt(tokenizer.nextToken());
			month = Integer.parseInt(tokenizer.nextToken());
			day = Integer.parseInt(tokenizer.nextToken());

			// add person to the list (insert your code here)
			Person friend = new Person(firstName, lastName, email, year, month,
					day);

			// add it to the array of friends
			// if array is not big enough, double its capacity automatically
			if (numFriends == friendList.length)
				expandCapacity();

			// add reference to friend at first free spot in array
			friendList[numFriends] = friend;
			numFriends++;

		} while (!reader.endOfFile());

		reader.close();
	}

	// write list method, writes a list
	public void writeList(String fileName) {

		OutStringFile writer = new OutStringFile(fileName);
		System.out.println("Writing file to: " + fileName);

		String line = null;
		for (int i = 0; i < numFriends; i++) {
			line = friendList[i].toString();
		}
		writer.write(line);

	}

	/**
	 * add method adds a person to the list
	 * 
	 * @param firstName
	 *            first name
	 * @param lastName
	 *            last name
	 * @param email
	 *            email address
	 */
	public void add(String firstName, String lastName, String email) {
		// create a new Person object
		Person friend = new Person(firstName, lastName, email);

		// add it to the array of friends
		// if array is not big enough, double its capacity automatically
		if (numFriends == friendList.length)
			expandCapacity();

		// add reference to friend at first free spot in array
		friendList[numFriends] = friend;
		numFriends++;
	}

	/**
	 * second add method, with year month and day as birthday parameters
	 * 
	 * @param firstName
	 * @param lastName
	 * @param email
	 */
	public void add(String firstName, String lastName, String email, int year,
			int month, int day) {
		// create a new Person object
		Person friend = new Person(firstName, lastName, email, year, month, day);

		// add it to the array of friends
		// if array is not big enough, double its capacity automatically
		if (numFriends == friendList.length)
			expandCapacity();

		// add reference to friend at first free spot in array
		friendList[numFriends] = friend;
		numFriends++;
	}

	/**
	 * remove method removes a specified friend from the list
	 * 
	 * @param firstName
	 *            first name of person to be removed
	 * @param lastName
	 *            last name of person to be removed
	 * @return true if friend was removed successfully, false otherwise
	 */
	public boolean remove(String firstName, String lastName) {
		final int NOT_FOUND = -1;
		int search = NOT_FOUND;
		Person target = new Person(firstName, lastName, "");

		// if list is empty, can't remove
		if (numFriends == 0) {
			return false;
		}
		// search the list for the specified friend
		for (int i = 0; i < numFriends && search == NOT_FOUND; i++)
			if (friendList[i].equals(target))
				search = i;

		// if not found, can't remove
		if (search == NOT_FOUND)
			return false;

		// target person found, remove by replacing with last one in list
		friendList[search] = friendList[numFriends - 1];
		friendList[numFriends - 1] = null;
		numFriends--;

		return true;
	}

	// find friend method
	public Person findFriend(Person target) {
		int position = -1;
		// search the list for the target friend
		for (int i = 0; i < numFriends; i++)
			if (friendList[i].equals(target))
				position = i;
		if (position == -1) {
			System.out
					.println("Sorry, that person is not in the contacts. Please try a different name");
			return null;
		} else
			return friendList[position];

	}

	/**
	 * toString method loops thru a person array and returns the first name,
	 * last name, email, and (if valid) birthdy of the person
	 * 
	 */
	public String toString() {
		String s = "";
		for (int i = 0; i < numFriends; i++) {
			s = s + friendList[i].toString() + "\n";
		}
		return s;
	}

	/**
	 * expandCapacity method is a helper method that creates a new array to
	 * store friends with twice the capacity of the existing one
	 */
	private void expandCapacity() {
		Person[] largerList = new Person[friendList.length * 2];
		for (int i = 0; i < friendList.length; i++)
			largerList[i] = friendList[i];

		friendList = largerList;
	}

	/**
	 * 
	 * @return numFriends - the number of friends of the person
	 */
	public int getNumFriends() {
		return numFriends;
	}

	public void clearFriends() {
		numFriends = 0;
	}

}



The Instring file:

import java.io.*;

/**
 * InStringFile makes file reading simpler. It allows information to be read one
 * line at a time from a data file, as a String.
 * 
 * @author CS1027
 */
public class InStringFile {

	/**
	 * the handle to read in the file
	 */
	private BufferedReader in;
	/**
	 * the next line of the file to be read
	 */
	private String nextLine;

	/**
	 * Constructs the object that controls file reading Exits gracefully if file
	 * not found or file cannot be read
	 * 
	 * @param filename
	 *            the name of the file to be read
	 */
	public InStringFile(String filename) {
		try {
			in = new BufferedReader(new FileReader(filename));
			nextLine = in.readLine();
		} catch (FileNotFoundException ee) {
			System.out.println("File " + filename + " not found.");
			System.exit(0);
		} catch (IOException e) {
			System.out.println("File " + filename + " cannot be read.");
			System.exit(0);
		}
	}

	/**
	 * Reads the next line of input as a String Exits gracefully if an error
	 * occurs while reading the file
	 * 
	 * @return the next line from the input file
	 */
	public String read() {
		String current = nextLine;
		try {
			nextLine = in.readLine();
		} catch (IOException e) {
			System.out.println("File cannot be read.");
			System.exit(0);
		}
		return current;
	}

	/**
	 * Lookahead test for end of input
	 * 
	 * @return true if end of file has been reached
	 */
	public boolean endOfFile() {
		return (nextLine == null);
	}

	/**
	 * Closes the file (making it inaccessible though this InStringFile)
	 */
	public void close() {
		try {
			in.close();
			in = null;
		} catch (IOException e) {
			System.out.println("Problem closing file.");
			System.exit(0);
		}
	}
}


the outstring file:

import java.io.*;

/**
 * OutStringFile makes file writing simpler. It allows information to be written
 * one line at a time to a data file, as a String.
 * 
 * @author CS1027
 */
public class OutStringFile {

	/**
	 * the handle to write to the file
	 */
	private BufferedWriter out;

	/**
	 * Constructs the object that controls file writing Exits gracefully if
	 * unable to write to file
	 * 
	 * @param filename
	 *            the name of the file to be written to
	 */
	public OutStringFile(String filename) {
		try {
			out = new BufferedWriter(new FileWriter(filename));
		} catch (IOException e) {
			System.out.println("File " + filename + " cannot be written.");
			System.exit(0);
		}
	}

	/**
	 * Writes a line of output as a String Exits gracefully if an error occurs
	 * while writing the file
	 * 
	 * @param the
	 *            line to be written
	 */
	public void write(String line) {
		try {
			out.write(line);
		} catch (IOException e) {
			System.out.println("File cannot be written.");
			System.exit(0);
		}
	}

	/**
	 * Closes the file (making it inaccessible though this OutStringFile)
	 */
	public void close() {
		try {
			out.close();
			out = null;
		} catch (IOException e) {
			System.out.println("Problem closing file.");
			System.exit(0);
		}
	}
}


Was This Post Helpful? 0
  • +
  • -

#8 Flukeshot  Icon User is offline

  • A little too OCD
  • member icon

Reputation: 417
  • View blog
  • Posts: 1,030
  • Joined: 14-November 12

Re: I am thoroughly confused by "bufferedWriter" and "FileWrit

Posted 01 July 2013 - 05:52 PM

If I'm not mistaken, this stack trace is identical to the one discussed in This thread.

Try getting rid of your .metadata folder in your eclipse workbench. I feel like your IDE is corrupted and a clean uninstall/reinstall would be appropriate.
Was This Post Helpful? 0
  • +
  • -

#9 Dylsauce  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 98
  • Joined: 30-June 13

Re: I am thoroughly confused by "bufferedWriter" and "FileWrit

Posted 01 July 2013 - 06:32 PM

full reinstall - I still get the same error :(
Exception in thread "main" java.lang.RuntimeException: Invalid date
at Date.<init>(Date.java:18)
at Person.<init>(Person.java:47)
at SocialNetwork.readList(SocialNetwork.java:71)
at TestSocialNetwork.main(TestSocialNetwork.java:22)


I don't understand why my Date class doesn't override the already existing date class?
Was This Post Helpful? 0
  • +
  • -

#10 Flukeshot  Icon User is offline

  • A little too OCD
  • member icon

Reputation: 417
  • View blog
  • Posts: 1,030
  • Joined: 14-November 12

Re: I am thoroughly confused by "bufferedWriter" and "FileWrit

Posted 01 July 2013 - 06:47 PM

import java.util.*;


Probably this.
Was This Post Helpful? 0
  • +
  • -

#11 Dylsauce  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 98
  • Joined: 30-June 13

Re: I am thoroughly confused by "bufferedWriter" and "FileWrit

Posted 01 July 2013 - 06:53 PM

Deleting that means that I can't use the tokenizer class which i need. Is there a way to keep it, but use my own Date class?
Was This Post Helpful? 0
  • +
  • -

#12 Dylsauce  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 98
  • Joined: 30-June 13

Re: I am thoroughly confused by "bufferedWriter" and "FileWrit

Posted 01 July 2013 - 07:07 PM

I should mention that I actually get:
Enter name of the file to read from: 
/users/dylsauce/desktop/FriendList.txt

Reading from file /users/dylsauce/desktop/FriendList.txt

Exception in thread "main" java.lang.RuntimeException: Invalid date
	at Date.<init>(Date.java:18)
	at Person.<init>(Person.java:47)
	at SocialNetwork.readList(SocialNetwork.java:71)
	at TestSocialNetwork.main(TestSocialNetwork.java:22)


Was This Post Helpful? 0
  • +
  • -

#13 Flukeshot  Icon User is offline

  • A little too OCD
  • member icon

Reputation: 417
  • View blog
  • Posts: 1,030
  • Joined: 14-November 12

Re: I am thoroughly confused by "bufferedWriter" and "FileWrit

Posted 01 July 2013 - 07:08 PM

Use the qualified name of the class you want to use. When you import a wildcard, you import everything in the package. Including Date.

import java.util.StringTokenizer;

This post has been edited by Flukeshot: 01 July 2013 - 07:11 PM
Reason for edit:: Added code example

Was This Post Helpful? 0
  • +
  • -

#14 Dylsauce  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 98
  • Joined: 30-June 13

Re: I am thoroughly confused by "bufferedWriter" and "FileWrit

Posted 01 July 2013 - 07:15 PM

ah that makes sense - but alas it was the same result as before. Is there any way you could copy and paste it into your IDE and see if it runs?
Was This Post Helpful? 0
  • +
  • -

#15 Flukeshot  Icon User is offline

  • A little too OCD
  • member icon

Reputation: 417
  • View blog
  • Posts: 1,030
  • Joined: 14-November 12

Re: I am thoroughly confused by "bufferedWriter" and "FileWrit

Posted 01 July 2013 - 07:30 PM

Unfortunately, it does.

I'm not sure what exactly is going on but you might need to take this issue to the eclipse developers themselves.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2