I have to read a int number 8 from the file and then saves the output into the same file. Everything works good but somehow the output is not display into the file. I don't know what's wrong. Any help will be appreciated.
import java.util.Scanner;
import java.io.*;
public class RomanNumerals
{
public static void main(String[] args)throws IOException
{
// Reading data from the file.
Scanner inputFile = new Scanner(new FileReader("C:\\Users\\IRC115\\Documents\\NumberValue.txt"));
// Declare the variable.
int number;
// Reading the value from the file.
number = inputFile.nextInt();
// Close the input file.
inputFile.close();
// Create the PrintWriter Object.
FileWriter fwriter =
newFileWriter("C:\\Users\\IRC115\\Documents\\NumberValue.txt",true);
PrintWriter outputFile =
new PrintWriter(fwriter);
The path of the file is correct. I am not getting error when I execute the program. Is the switch statment is correct? I don't see any error.
switch (number)
{
case 1:
outputFile.println("I");
break;
case 2:
outputFile.println("II");
break;
case 3:
outputFile.println("III");
break;
case 4:
outputFile.println("IV");
break;
case 5:
outputFile.println("V");
break;
case 6:
outputFile.println("VI");
break;
case 7:
outputFile.println("VII");
break;
case 8:
outputFile.println("VIII");
break;
case 9:
outputFile.println("IX");
break;
case 10:
outputFile.println("X");
break;
default:
outputFile.println("Invalid number.");
// Close the output file.
outputFile.close();
}