

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
How to use java's string manipulation methods and file i/o techniques, focusing on scanner, bufferedreader, filewriter, and printwriter. It also includes an exercise to design a program that counts the occurrences of a given word in a file and displays the line numbers where it appears.
Typology: Exams
1 / 2
This page cannot be seen from the preview
Don't miss anything!
Scanner scan = new Scanner(new File(”myfile.txt")); String s; while(scan.hasNext()) {//acts like an iterator s = scan.nextLine(); }
BufferedReader in = new BufferedReader(new FileReader(”myfile.txt")); s = in.readLine(); //returns null when EOF reached while(s != null) { s = in.readLine(); } in.close(); //remember to CLOSE the file!
PrintWriter out = new PrintWriter(new FileWriter(”myfile.txt")); out.println(“String 1”); out.println(“String 2”); out.close(); //remember to CLOSE the file!