English
Follow Us Online
Twitter    YouTube(TM)
Append to file
Append String to File
Add to String Array
Add to Object Array
Add Char to String
Access Inner Class
Access Outer Class
Break out of for loop
Convert String to int
Convert int to String
String to Date object
Convert Double to int
Convert double to int
Call a method
Call method in Class
Call a Class
Call Super Class method
Check if a file exists
Check String is Number
Declare a variable
Declare a String
Declare an Array
Declare constants
Define enum
Define a method
Exit program
Exit a for loop
Exit a method
Format date
Format double
Find current directory
Get current date
Get user input
Get Class name
Java How to A B C D E F G H I J K L M N O P Q R S T U V W Y W Z
More How to A1
Java How to Append to a file
Java How to Append String to a file
Related Links Append to a file Append String to a file Add to String Array Add to Object Array Next Page >>>
Steps:
  1. Create an instance of FileWriter with the file name and boolean append indicator (true) as argument.
  2. Create an instance of BufferedWriter passing the instance of FileWriter.
  3. Call write method on instance of BufferedWriter to write to a file.
  4. Finally close the BufferedWriter stream.
	/**
	 * Writes the content of inputString to the file
	 * 
	 * @author www.f5java.com
	 * @param inputString : Content to write to the file
	 * @return : void
	 */
	public void writeToFile(String inputString) {
		try {
			// 1. Create FileWriter
			FileWriter fileStream = new FileWriter("output.txt", true);
			// 2. Create a buffered character-output stream
			BufferedWriter out = new BufferedWriter(fileStream);
			// 3. Writes to a content of inputString to file
			out.write(inputString);
			out.close(); // 4. Close the output stream
		} catch (IOException e) {
			System.out.println("Unable to write to file :" + e.getMessage());
		}
	}
													
Java How to Add to an element to String Array
Steps:
  1. Create and initialize a String array.
  2. Add the String element at given index using assignment.
	/**
	 * Example showing adding element to String Array
	 * 
	 * @author www.f5java.com
	 * @return : void
	 */
	public void addToStringArray() {
		// 1. Create and initialize a String array
		String[] stringArray = new String[10];
		// 2. Add the String element at given index using assignment
		stringArray[0] = "First String";
	}
													
Java How to Add to an element to Object Array
Steps:
  1. Create and initialize an Object array.
  2. Add the elements at given index using assignment.
	/**
	 * Example showing adding Objects to Object array
	 * 
	 * @author www.f5java.com
	 * @return : void
	 */
	public void addToObjectArray() {
		// 1. Create and initialize an Object array
		Object[] objectArray = new Object[10];
		// Adding String in to an Object array
		objectArray[0] = "First String";
		// Adding Integer Object in to an array
		objectArray[1] = new Integer("10");
		// Adding Boolean Object in to an array
		objectArray[2] = new Boolean("true");
	}