QUOTE(j_delong @ 27 Aug, 2008 - 03:10 PM)

Working on another project. I have a program set up to read from a file, I then need to insert indents into the paragraphs. The problem is I need the program to check for blank lines because my first paragraph is not indenting nor my last paragraph (because there were 2 blank lines before it.) From what I am told from others the easiest way to do this is to set a boolean to true if it finds a blank line and then have it print the blank spaces for indents. How do I set a boolean expression and where does it go in the program? I have printed out a lot of material on booleans and it still isn't making any sense to me.
Don't really need a boolean. Just print (not println) when you have a blank line
CODE
import java.io.*;
public class History
{
public static BufferedReader inFile;
public static PrintWriter outFile;
public static void main(String [] args) throws IOException
{
String line;
inFile = new BufferedReader(new FileReader("history.dat"));
outFile = new PrintWriter(new FileWriter("historyd2.out"));
line = inFile.readLine();
outFile.print(" "); // beginning
while (line !=null)
{
if(line.trim().length() == 0) // trim to remove blanks
{
// emptyline
outFile.println(); // print empty line
outFile.print(" "); // beginning of following one
}
else
{
outFile.println(line); // regular line
}
line = inFile.readLine();
}
}
outFile.close();
inFile.close();
}
}
This post has been edited by pbl: 27 Aug, 2008 - 02:34 PM