wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Please help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please help!" Watch "Please help!" New topic
Author

Please help!

Vince Snow
Greenhorn

Joined: Aug 25, 2007
Posts: 9
Hello,

I have been trying to create some program that reads from the text file and inserts 3 spaces at the beginning of each new paragraph and finally outputs the result to another text file.


Please help:


import java.io.*;



public class Paragraphs {

public static void main(String[] args) throws IOException {

// create read and write files

File inputFile = new File("hi.dat");

File outputFile = new File("d.out");



// create two File Streams

FileReader in = new FileReader(inputFile);

FileWriter out = new FileWriter(outputFile);



// read file and write it to another

int b;



while ((b = in.read()) != -1)

out.write(b);



// close files

in.close();

out.close();

}

}
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14116
    
  16

Ok, so what is it exactly that you want help with? Please explain exactly what the problem is. Also, please use a meaningful subject line (instead of "Please help!"). When you post code, you can use code tags so that the forum software can properly format the code.
[ September 10, 2007: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Vince Snow
Greenhorn

Joined: Aug 25, 2007
Posts: 9
The program should read the text file, insert 3 spaces at the beginning of the new paragraph and send the indented output to another text file.

In the mean time, it reads the text file and sends it to another file.
That's all it does.
I do not know how to make it insert spaces before the paragraphs.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

Here's the original source code, cleaned up to be more readable:




This is a good start - assuming it works (i haven't tested that). My first question is how can you tell if you are at the start of a new paragraph or not?

don't tell me in code, tell me in english first. once you can do that, try writing the code. stick something like

if (beginning of new paragraph){
print "I'm starting a new paragraph"
}

get that to work before you insert three spaces...
[ September 10, 2007: Message edited by: Fred Rosenberger ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Vince Snow
Greenhorn

Joined: Aug 25, 2007
Posts: 9
The program should check for the blank line, if the next line is blank it should insert spaces at the beginning of the next line.
That's where the problem lies. I do not know how to code it.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

do you know how to tell if a line is blank?
Vinay Nag
Greenhorn

Joined: Sep 08, 2007
Posts: 3
You can actually check for the \r or \n and then check for the "". This should give you if it is a blank line.
Vince Snow
Greenhorn

Joined: Aug 25, 2007
Posts: 9
I have updated the code but still trying to figure out what to do.
Any help would be greatly appreciate since I only started working with Java two months ago and I totally new to programming.

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

We are trying to help you. What we will not do is give you the answer.

So, again, how can you tell if a line is blank? if you don't know how to do it in Java, tell us how you'd do it in english, and we'll then work towards changing that into java.
Vince Snow
Greenhorn

Joined: Aug 25, 2007
Posts: 9
The blank line has its length < 1
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please help!