TabFilter.java Source code

Java tutorial

Introduction

Here is the source code for TabFilter.java

Source

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

class TabFilter {

    public static void main(String args[]) throws Exception {
        FileReader fr = new FileReader(args[0]);
        BufferedReader br = new BufferedReader(fr);

        FileWriter fw = new FileWriter(args[1]);
        BufferedWriter bw = new BufferedWriter(fw);

        // Convert tab to space characters
        String s;
        while ((s = br.readLine()) != null) {
            for (int i = 0; i < s.length(); i++) {
                char c = s.charAt(i);
                if (c == '\t')
                    c = ' ';
                bw.write(c);
            }
        }

        bw.flush();
        fr.close();
        fw.close();
    }
}