Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import acm.program.ConsoleProgram;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.util.Scanner;
- public class Task1 extends ConsoleProgram {
- public void run() {
- String allFile = fileReader();
- CharSequence toReplace = readLine();
- CharSequence newLine = readLine();
- println(doTask(allFile,toReplace,newLine));
- }
- public String fileReader() {
- FileReader fr = null;
- try {
- fr = new FileReader("C:\\Users\\БарабухаМаріяМаксимі\\Desktop\\workspace\\pract11\\src\\pract11\\in.txt");
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- Scanner scan = new Scanner(fr);
- String str = "";
- boolean f = true;
- while (scan.hasNextLine()) {
- if (f) {
- f = false;
- str = scan.nextLine();
- } else
- str = str + "\n" + scan.nextLine();
- }
- return str;
- }
- public String doTask(String allFile, CharSequence toReplace, CharSequence newLine) {
- return allFile.replace(toReplace,newLine);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement