-1

Hello i am trying to make a programm that is reading input from a .txt and then places it into an other .txt with some changes.. Println is used just to test the results

INPUT :


This should be changed

I dont know why it doest change

What is wrong..


RESULTS :


This should be changed

This should be changed

I dont know why it doest change

I dont know why it doest change

What is wrong..

What is wrong..


import java.io.* ; 
public class dunno
{
    public static void main(String[] args)
    {
        BufferedReader inputStream = null;
        PrintWriter outputStream = null ;
        try
        {
            inputStream =new BufferedReader(new FileReader("in.txt"));
            outputStream =new PrintWriter(new FileWriter("out.txt"));

            String k;
            while ((k = inputStream.readLine()) != null ){
               System.out.println(k);
               k.replace("s","p");
               System.out.println(k);
               outputStream.println(k + " edited_line");
            }
            if (inputStream != null){
                inputStream.close();
            }
            if (outputStream != null){
                outputStream.close();
            }
        }
        catch(IOException e){
                System.out.println("try again.");
        }
    }
 }
TrueBee
  • 13
  • 2

1 Answers1

2

Strings are immutable. It should be:

k = k.replace("s","p");
brso05
  • 13,142
  • 2
  • 21
  • 40
  • Who downvoted the correct answer and why? At least say why you downvote that way the person has a chance to fix the issue (if there really is one...). – brso05 Apr 13 '16 at 12:24