Wednesday, 23 February 2022

Write a ‘java’ program to copy only non-numeric data from one file to another file

 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 :


Write a ‘java’ program to copy only non-numeric data from one file to another file

Code :


Write a ‘java’ program to copy only non-numeric data from one file to another file


Destination File after code :


Write a ‘java’ program to copy only non-numeric data from one file to another file



No comments:

Post a Comment

Write a Java program to display given extension files from a specific directory on server machine.

 DOWNLOAD     SLIP14Q2 /** * STEPS TO RUN CODE * Step 01 compile the code * Step 02 run the code * Step 03 give a file directory locatio...