Java Delemma

  • From: "Gilbert Neiva" <gneiva@xxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Mon, 28 Jun 2010 13:26:42 -0600

I'm trying to write an application which takes an input file, and adds 5 blank 
spaces at the beginning of each paragraph. Then the application is to write to 
an output file with the new changes. The application will detect the beginning 
of a new paragraph because there is a blank line before it. I test for the 
blank using the following if statement.

if inputString.length() < 1
{
inputString = blanks+inFile.hasNextLine();
}

When I tried to compile the application using the javac program, I get the 
following error.

History.java:23: incompatible types
found   : boolean
required: java.lang.String
inputString = inFile.hasNextLine();
^
1 error 

The source code for the application is below.

import java.io.*; // importing input.output classes

import java.util.Scanner;


public class History

{

public static Scanner inFile;

public static PrintWriter outFile;


public static void main(String[] args)

{

String inputString; // Input string from a line in file

final String blanks = " ";

// Five blanks inserted at beginning of each paragraph

inFile = new Scanner(new FileReader("history.d1"));

// Instantiating new scanner and new filereader object with

// history.d1 as argument

outFile = new PrintWriter(new FileWriter("history.d2"));

// Instantiating new printWriter object

// It will be used to write to a file

inputString = blanks+inFile.hasNextLine();

outFile.println(inputString);


while (inFile.hasNextLine())

{

inputString = inFile.hasNextLine(); 


if (inputString.length() < 1)

{

inputString = blanks+inFile.hasNextLine(); 

}

outFile.println(inputString);

}

inFile.close();

outFile.close();

}

}



What am I doing wrong?



Gilbert Neiva


Other related posts: