Develop an application to remove whitespaces from given text file using IOStream Methods
Problem
Statement :
Write a program to remove
whitespaces from a text file. Name of the file is given using
command line
Introduction
String trim()
This method returns a
copy of the string, with leading and trailing whitespace omitted.
public
String trim()
It
returns a copy of this string with leading and trailing white space removed, or
this string if it has no leading or trailing white space.
Program
import java.util.*;
import java.io.*;
class exp10
{
public static void main(String args[])
{
FileReader fr ;
BufferedReader br ;
String ln;
FileWriter fw;
try
{
fr = new FileReader("aabbcc.txt");
br = new BufferedReader(fr);
fw = new FileWriter("xyz.txt");
while((ln = br.readLine())!=null)
{
ln = ln.trim();
if(!ln.equals(""))
{
fw.write(ln);
}
}
fr.close();
fw.close();
}
catch(IOException e)
{
System.out.println(e);
}
}
}
Tags:
java