RE: Java Delemma

  • From: "Sina Bahram" <sbahram@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Mon, 28 Jun 2010 15:37:40 -0400

hasNextLine returns a boolean.

You mean nextLine perhaps?

Take care,
Sina

________________________________

From: programmingblind-bounce@xxxxxxxxxxxxx 
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Gilbert Neiva
Sent: Monday, June 28, 2010 3:27 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Java Delemma


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


__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: