Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unhandled exception type IOException

807599Mar 14 2007 — edited Mar 14 2007
Plz tell me what i have done wrong, or what i have forgotten to do here is my code:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;

public class Zamiennik {

void change(String name,String szukany,String zamieniony) 
throws IOException {
	
        BufferedReader inputStream = null;
        PrintWriter outputStream = null;
        
        try {
            inputStream = 
                new BufferedReader(new FileReader(name));
            outputStream = 
                new PrintWriter(new FileWriter(name));

            String bufor;
            while ((bufor = inputStream.readLine()) != null) {
    			if(bufor.indexOf(szukany)!= -1)
    	        {
    				bufor.replaceAll(szukany,zamieniony);

                    outputStream.println(bufor);
    	        }
            }
        } 
        
        catch(IOException err)
        {System.out.println(err);}
        
        finally {
            if (inputStream != null) {
                inputStream.close();
            }
            if (outputStream != null) {
                outputStream.close();
            }
        }
    }


	public static void main(String[] args) {
		
		Zamiennik test = new Zamiennik();
		test.change("test.txt","xxx","zmiana");
	}

}
and here is my error:
Unhandled exception type IOException
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 11 2007
Added on Mar 14 2007
2 comments
3,554 views