Tuesday, 23 July 2019

Simple guidance for you in Java Filewriter Blog


Java filewriter is needed into every programmer for creating and write files in Java. There are many classes in Java that can be used to write to file. This java filewriter blog will let you know about java filewriter class.

Filewriter class creates a writer that can be sued to write a file. Filewriter is a part of the java.io package. It is the sub-class of writer class. Filewriter doesn’t depend on whether the file exists or not. If the file does not exist, then, filewriter will create the file before opening it for output at the time of object creation.

 Java filewriter is mainly used to write character-oriented data to a file. It is the character-oriented class which is used for file handling in Java. It is the most convenient way to write files. The syntax is also easy to read and understand. It directly writes into a file and should be used only when the writers are less.



Syntax of Java filewriter:

Public class Filewriter extends outputstream Writer

Constructors of Java Filewriter

Filewriter (string file): it creates a file. It gets the file name in a String.

Filewriter (File File): it creates a file. It gets the file name in the file object. It throws an IOexception if the file exists but is a directory rather than a regular file. 

Filewriter (filedescriptor fd): it creates a file object related with a specified file descriptor.

Filewriter (file, Boolean append): it creates the filewriter object using the specified file object. The bytes will be written at the end of the file, not at the beginning if the second argument is true.

Filewriter (string filename, Boolean append): it creates a filewriter object using a specified filename with a Boolean indicating whether or not to append the data written.

Methods of Java Filewriter

Void write (string Text): If you want to write String to the file, this method can be used with filewriter.

Void write (char c): If you want to write Char to the file, this method can be used with filewriter.

Void write (char[] c): You can use this method to write a character array in the filewriter.

Void flush (): This should be used if you want to flush out the data in the filewriter.

Void close (): As the name suggests, this can be used to close the filewriter.

We hope that this Java filewriter blog will help you in writing a file in Java. It includes the syntax, methods and constructors of filewriter.

Monday, 3 June 2019

Know more About the Java Filewriter Class with Examples


In detail, the Java FileWriter class is generally used to write character-oriented data to a file. Besides, this is a character-oriented class which is used to handle file in Java smoothly. Different from File Output Stream class, there is no need to convert the strings into a byte array. The reason behind this is Java File Writer provides an easy method to write the string directly. Let’s know more about Java FileWriter.



·      This class is a major part of Java.io package.
·      File writer is the subclass of Java.io Output Stream Writer Class.
·     The File Writer is meant for writing the streams of characters.
·    This is widely used to write character files. It’s written () method lets you write charter (s) or the string to the file.

·    The higher-level Writer objects generally wrap the File Writers. For example, BufferedWriter or PrintWriter. Such Java File Writer provides a better performance, higher-level, and different flexible methods to write important data.

Methods of using File writer

1.      Public Void Write (int c) gives IO Exception- It writes a single character.

2.      Public Void Write (Char [] stir) gives IOException – It writes an array of characters.

3.      Void Write (String Str) gives IO Exception- This writes a string.

4.      Public Void File Write (String Str. Int off. Int Len) gives IO Exception- It creates a part of the string. However, the of is offset, and from there, you will have started writing the characters. Len is the number of characters to write.

5.      Public Void Flush () gives IO Exception- It flushes the stream

6.      Public Void Close () gives IO Exception- It provides the stream first and after that closes the Java File Writer.

Example of Java FileWriter
In this example, you can learn about how to write the data ion the testout.txt file using Java File Writer class.

package com.javatpoint; 
import java.io.FileWriter; 
public class FileWriterExample { 
public static void main (String args[]){   
try {
FileWriterfw=new FileWriter("D:\\testout.txt");  
fw.write("Welcome to javaTpoint.");   
w.close();   
} catch (Exception e) {System.out.println(e);}   
System.out.println("Success...");   
}   
} 

Understand the File output Stream and File Writer Stream

·         The File Writer is designed to write stream of characters while the File Output Stream is generally used to write raw bytes streams.

·         The File Writer deals with the 16-bit characters. But the FileOutputStream works with 8-bit bytes.
·         The File Writer can easily handle Unicode strings. On the other hand, File Output Stream does not accept characters or strings.

Friday, 3 May 2019

Learn the Concept of Call by Reference in C Programming Language


Call by reference is one of a couple of methods meant for passing the data within the function in C language. It is here to mention that there are a couple of methods, called the ‘call by value and call by reference’ available to pass the data within the function in C.

In call by reference, the variable’s address is put inside the function call as the actual parameter. Actual parameter’s value can be changed upon making changes in the basic parameters after the address of the actual parameters is put. 



The way of allocating memory is quite identical for formal parameters, as well as the actual parameters in case of call by reference. The entire actions in the functions are done as per the value kept at the address of the actual parameters; also at the same address, the changed value gets stored.

What does it mean by function call by reference?

Upon a function being called by putting the address of actual parameters, it is the method of calling the function, called as the call by reference. In case of call by reference, the actions taken are all the formal parameter, which affects the actual parameter’s value as the entire job is done on the value stored within the actual parameter’s address. 

In case of call by reference, the method of putting arguments within a function is about copying the address of an argument within the formal parameter. Within the function, the address is made use of for accessing the actual argument that is used in the concerned call. This tells that the changes made to the parameter affect the argument that is passed in.

In case of call by reference value passing, an argument pointer is delivered within the functions very much as of any other conventional value. In accordance, the coder needs to provide the function parameters as pointer types that make the exchange of the values of both the integer variables pointed to, through their arguments.

Difference between call by value and call by reference

It is important to understand the difference between call by value and call by reference as most people confuse while distinguishing between the two. In case of call by value, a copy of the value is delivered within the function. In case of call by reference, the address of value is put into the function.

When it comes about the call by value, the changes made within the function is confined within the function only. Here the values of the actual parameters don’t alter upon altering the formal parameters. On the other hand, in case of call by reference, changes made within the function are validated at the exterior of the functions as well. Here the values of the actual parameters do alter upon changing the formal parameters.

In case of call by value, the actual and formal arguments are developed at distinct memory locations. When it comes about the call by reference, both the actual and formal arguments are made within the same memory location.

Simple guidance for you in Java Filewriter Blog

Java filewriter is needed into every programmer for creating and write files in Java. There are many classes in Java that can be used to ...