Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help!

 
Vince Snow
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Vince Snow
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12125
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Vince Snow
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12125
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you know how to tell if a line is blank?
 
Vinay Nag
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12125
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The blank line has its length < 1
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic