Please help!
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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();
}
}
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();
}
}
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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 ]
[ September 10, 2007: Message edited by: Jesper Young ]
Vince Snow
Greenhorn
Posts: 9
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
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.
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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 ]
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
Posts: 9
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
That's where the problem lies. I do not know how to code it.
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
do you know how to tell if a line is blank?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
Any help would be greatly appreciate since I only started working with Java two months ago and I totally new to programming.
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
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.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Vince Snow
Greenhorn
Posts: 9
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The blank line has its length < 1
| Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |











