Slip 1 Q 2
Save as "Slip1q2.java"
import java.io.*;
public class Slip1q2 {
public static void main(String[] args) throws IOException {
System.out.println("reading file...");
FileReader fileReader = new FileReader("Slip1/src/sourcefile1q2.txt");
// enter your source file location
FileWriter fileWriter = new FileWriter("Slip1/src/destinationfile1Q2.txt");
// enter your destination file location
int data = fileReader.read();
System.out.println("writing file...");
while (data != -1){
String content = String.valueOf((char)data);
if(Character.isAlphabetic(data)) {
fileWriter.append(content);
}else if(content.equals(" ")){
fileWriter.append(" ");
}
data = fileReader.read();
}
System.out.println("\nCOPY FINISHED SUCCESSFULLY...");
fileWriter.close();
fileReader.close();
}
}
OUTPUT:
Source file content :
Code :
Destination File after code :
No comments:
Post a Comment