write a program that checks a text file for several formatti

write a program that checks a text file for several formatting and punctuation matters. The program ask for the names of both an inputfile and an output file. It then copies all the text from the input file to the output file, but with the following two changes: (1) any string of two or more blank characters is replaced by a single blank; (2) all sentences start with an uppercase letter. All sentences after the first one begin after either a period, a question mark, or an exclamation mark that is followed by one or more whitespace characters.

Solution

package sample;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileOutputStream;

import java.io.FileReader;

import java.io.IOException;

import java.io.OutputStreamWriter;
public class lib{

public static void main(String[] args){

String inFile = \"C:\\\\Users\\\\Sandeep\\\\Desktop\\\\input.txt\";

String outFile = \"C:\\\\Users\\\\Sandeep\\\\Desktop\\\\output.txt\";

try {

File file = new File(inFile);

FileReader fileReader = new FileReader(file);

BufferedReader bufferedReader = new BufferedReader(fileReader);

String line;

File fout = new File(outFile);

FileOutputStream fos = new FileOutputStream(fout);

BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));

while ((line = bufferedReader.readLine()) != null) {
   line.replaceAll(\"\\\\s{2,}\",\" \"); //condition 1
   StringBuilder sb=new StringBuilder(line);
   if(sb.length()>1)
   sb.replace(0,1,sb.substring(0,1).toUpperCase()); // condition 2
bw.write(new String(sb));
bw.newLine();
}

fileReader.close();

bw.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

write a program that checks a text file for several formatting and punctuation matters. The program ask for the names of both an inputfile and an output file. I
write a program that checks a text file for several formatting and punctuation matters. The program ask for the names of both an inputfile and an output file. I

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site