why do I recive a cannot find symbol variable outputStream

why do I recive a cannot find symbol - variable outputStream

in this line

outputStream = new PrintWriter( new FileOutputStream(\"numbered.txt\"));

this is the whole code


import java.util.Scanner;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

/**
* Write a description of class next here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class next
{
public static void main(String[] args) {
Scanner inputStream = null;
PrintWriter outpurtStream = null;

try {
inputStream =
new Scanner( new FileInputStream(\"original.txt\"));
outputStream = new PrintWriter( new FileOutputStream(\"numbered.txt\"));
}
catch (FileNotFoundException e) {
System.out.println(\" File can not be found or open\");
System.exit(0);

}

string line = null;
int count = 0;
while( inputStream.hasNextLine( ))
{
line = inputStream.nextLine();
count++;
outputStream.println( count + \" \" + line);
}

inputStream.close();
outputStream.close( );
}}

Solution

The compiler tells you that the name (symbol) outputstream is not defined in the scope (and enclosing scopes) where you want to use it. i\'ve modifie code please check it

import java.util.Scanner;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
/**
* Write a description of class next here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class next
{
public static void main(String[] args) {
Scanner inputStream = null;
try {
inputStream = new Scanner( new FileInputStream(\"original.txt\"));
PrintWriter outputStream = new PrintWriter( new FileOutputStream(\"numbered.txt\"));
String line = null;
int count = 0;
while( inputStream.hasNextLine( ))
{
line = inputStream.nextLine();
count++;
outputStream.println( count + \" \" + line);
}
inputStream.close();
outputStream.close( );
}
catch (FileNotFoundException e) {
System.out.println(\" File can not be found or open\");
System.exit(0);
}
  
}}

why do I recive a cannot find symbol - variable outputStream in this line outputStream = new PrintWriter( new FileOutputStream(\
why do I recive a cannot find symbol - variable outputStream in this line outputStream = new PrintWriter( new FileOutputStream(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site