• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please help!

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();

}

}
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
do you know how to tell if a line is blank?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The blank line has its length < 1
 
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic