Erase Some Characters from Each Line of a Text File - Java Program
Minggu, 11 Agustus 2013
0
komentar
Following Java program erase user given fixed number of characters from each line of a text file. Here the number of characters to be erased is 3. For the convenience input and output files are given as two separate file. Output file may contain the result you want.
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;
public class CharEraser {
public static void main(String[] args) throws IOException {
String inputfile = "input.txt";
String outputfile = "output.txt";
int number_of_char_to_erased = 3;
String line = "";
File input = new File(inputfile);
Scanner scan = new Scanner(input);
File output = new File(outputfile);
PrintStream print = new PrintStream(output);
while (scan.hasNext()) {
line = scan.nextLine();
line = line.substring(number_of_char_to_erased);
print.println(line);
}
scan.close();
print.close();
}
}
Baca Selengkapnya ....





