Ex1: Ex2: Ex3: Write a programm which read a given .txt file line by line and creates a new b.txt file containing only the lines in even position import java.io.*; class CopiaEvenLines{ public static void main(String args[]) { String s; int i = 1; try { FileReader fr = new FileReader("a.txt"); BufferedReader br = new BufferedReader(fr); FileOutputStream f = new FileOutputStream("b.txt"); PrintStream os = new PrintStream(f); while ((s = br.readLine()) != null) { if (i % 2 == 0) os.println(s); i++; } fr.close(); os.close(); } catch (IOException e) { System.out.println("Errore di input/output: " + e); } } } Ex2: Write a program which read line by line a .txt file with a given name .txt and it writes in a new .txt file with name .txt the following lines Number of lines: xx Number of characters: yy where xx and yy are respectively the number of lines and characters contained in the input file. import java.io.*; class ContaRigheCaratteri{ public static void main(String args[]) { String s; int i = 0; int c = 0; try { FileReader fr = new FileReader("a.txt"); BufferedReader br = new BufferedReader(fr); FileOutputStream f = new FileOutputStream("b.txt"); PrintStream os = new PrintStream(f); while ((s = br.readLine()) != null) { c = c + s.length(); i++; } os.println("Numero righe lette:" + i); os.println("Numero caratteri letti:" + c); fr.close(); os.close(); } catch (IOException e) { System.out.println("Errore di input/output: " + e); } } } Ex3 write a programm which generate a .txt file by shuffeling two txt file. That is: if the generated file is named A.txt and the two files are B.txt and C.txt, then the first line of A.txt is the first line of B.txt, the second line of A.txt is the first line of B.txt, the third line of A.txt is the second line of B.txt, the fourth line of A.txt is the second line of B.txt, and so on import java.io.*; class ShaffleFiles{ public static void main(String args[]) { String s; try { FileReader fr1 = new FileReader("f1.txt"); BufferedReader br1 = new BufferedReader(fr1); FileReader fr2 = new FileReader("f2.txt"); BufferedReader br2 = new BufferedReader(fr2); FileOutputStream f = new FileOutputStream("unione.txt"); PrintStream os = new PrintStream(f); while ((s = br1.readLine()) != null) { os.println(s); } while ((s = br2.readLine()) != null) { os.println(s); } fr1.close(); fr2.close(); os.close(); } catch (IOException e) { System.out.println("Errore di input/output: " + e); } } } // 1. opening the file for writing (creation of the file) FileWriter f = new FileWriter("test.txt"); PrintWriter out = new PrintWriter(f); // 2. writing text on the file out.println("some text to write to the file"); // 3. closing the output channel and the file out.close(); f.close();