I am getting the following error while compiling the program
variable fos1 might not have been initialized
The code for the program is as follows:
package MyInputOutput;
import java.io.*;
public class CreateFile {
public static void main(String args[]) throws IOException{
FileOutputStream fos1;
char c;
String FilePath;
FilePath = "C:/Vishnu/Java Learning/Examples/MyInputOutput/";
FilePath = FilePath + args[0];
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
try{
fos1 = new FileOutputStream(FilePath);
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("Array index out of bounds");
}
do{
c = (char) obj.read();
if (c != 'z') {
fos1.write((int) c);
}
}while(c != 'z');
fos1.close();
Here I have declared fos1, but it is giving an error that
fos1 might not have been initialized.
How can i initialize fos1?
Appreciate your time.
thanks
variable fos1 might not have been initialized
The code for the program is as follows:
package MyInputOutput;
import java.io.*;
public class CreateFile {
public static void main(String args[]) throws IOException{
FileOutputStream fos1;
char c;
String FilePath;
FilePath = "C:/Vishnu/Java Learning/Examples/MyInputOutput/";
FilePath = FilePath + args[0];
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
try{
fos1 = new FileOutputStream(FilePath);
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("Array index out of bounds");
}
do{
c = (char) obj.read();
if (c != 'z') {
fos1.write((int) c);
}
}while(c != 'z');
fos1.close();
Here I have declared fos1, but it is giving an error that
fos1 might not have been initialized.
How can i initialize fos1?
Appreciate your time.
thanks