This is what i need

This is what i need

Implement a standalone procedure to read in a file containing words and white space and produce a compressed version of the file in an output file. The compressed version should contain all of the words in the input file and none of the white space, except that it should preserve lines.


for this question i need just :
one function can read string like (I like to play football)from a file (e.g,file.txt)then remove the spaces and the white spaces then just write this string in another file (e.g,file2.txt)as (Iliketoplayfootball)
without any compressing the file.

thank you
View Answers

February 20, 2010 at 5:13 PM

Hi Friend,

Try the following code:

import java.util.*;
import java.io.*;
import java.text.*;
import java.util.regex.*;

public class ReadFile{
public static void main(String args[]) throws Exception{
BufferedReader reader = new BufferedReader(new FileReader("c://data.txt";));
String line=null;

while ((line=reader.readLine())!=null){
String data = line.replaceAll(" ","");
FileWriter fstream = new FileWriter("out.txt",true);
BufferedWriter output = new BufferedWriter(fstream);
output.write(data);
output.newLine();
output.close();
}
}
}

Thanks









Related Tutorials/Questions & Answers:
This is what i need - Java Beginners
This is what i need  Implement a standalone procedure to read in a file containing words and white space and produce a compressed version of the file.... for this question i need just : one function can read string like (I like
what is java and why do i need it?
what is java and why do i need it?  Hi, Please tell me what is Java and why do i need it? Is it free to download? Also explain me how to write and test my first Java Application? What is the configuration or system requirement
Advertisements
What skills do I need for machine learning?
What skills do I need for machine learning?  Hi, I am beginner... to learn: What skills do I need for machine learning? Try to provide me good examples or tutorials links so that I can learn the topic "What skills do I need
What skills do I need to be a data analyst?
What skills do I need to be a data analyst?  Hi, I am beginner... to learn: What skills do I need to be a data analyst? Try to provide me good examples or tutorials links so that I can learn the topic "What skills do I need
This is what i need in this Question - Java Beginners
This is what i need in this Question  You are to choose between two... array. so i need your help to know is it correct or wrong Thank you... explaination with out coding In my understanding I choose the non-empty array
Java web development, what skills do I need?
Java web development, what skills do I need?  Java web development, what skills do I need
Java web development, what skills do I need?
Java web development, what skills do I need?  Java web development, what skills do I need
What do I need to do to use a MSSQL-Server with Web-Harvester?
What do I need to do to use a MSSQL-Server with Web-Harvester?  What do I need to do to use a MSSQL-Server with Web-Harvester
i want to do a project using jsp and servlet....What are all the materials i need to study
i want to do a project using jsp and servlet....What are all the materials i need to study   i want to do a project using jsp and servlet....What are all the materials i need to study ?   Please visit the following
I need an example of sessionfactory
I need an example of sessionfactory  Hi, I need an example of session factory in hibernate. If you can provide me one with, that would be great...Thanks
i need project
i need project  can u send online shoppin project 2 my mailid.   Please visit the following links: Struts2 Shopping cart JSP-Servlet Shopping cart
hello there i need help
hello there i need help  : i need to do a program like this: Automatic Teller Machine [B] Balance [D] Deposit [W] Withdrawal [Q] Quit select you... me with the codes and please explain to me how it works. i only need to use
I have need to help
I have need to help  Write a program that, for four points A, B, C and P, draws a triangle formed by ABC and a small cross showing the position of P; and displays a line of text indicating which of the following three cases
i need a help in this please
i need a help in this please  The factorial of a nonnegative integer n is written n! (pronounced ‚?? n factorial‚??) and is defined as follows: n!=n...=input.nextInt(); long num=m; for(int i=m;i>1;i
what is the need of... - Java Beginners
what is the need of...   what is the need of " return type like void ?   Hi Friend, In java, method always require a return type.The main method is the client code therefore jvm does not expected any return
I need Spring 2.5 example.
I need Spring 2.5 example.  Hello, I am looking forward to learn Spring framework and hence I need Spring 2.5 and Spring 3.0 example.. Thanks
I need to develop a gui like this
I need to develop a gui like this  Hai Friends, I need to develop such a menu in my gui programs. The gui contains 1 text field.whenever the text... please help me   sorry goes through this link I need to develop like
i need help to solve this problem
i need help to solve this problem  Write a stack class... and prints them in reverse order. and Show step by step what queue will look like.... H and I join the queue h. G leaves the queue i. H and I leave the queue
What we need data science?
What we need data science?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: What we need... learn the topic "What we need data science?". Also tell me which
i need program or code for this program
i need program or code for this program  out should be in this form 1 2 3 4 5 6 3 5 7 9 11 8 12 16 20 20 28 36 48 64 112
i need help - Development process
i need help  hello, i need help regarding this program. public...()); } } } it is printing the result of ping in to a file,but if i want... the result in to the files,if i want to do this i must make my program running
i need help - Development process
i need help  hello, i need help regarding this program. this program gives ping to the system. import java.net.*; import java.io.*; import... IPAddress on command line, but i want to take it dynamically and it must store
i need help plz .... Quickly
i need help plz .... Quickly   how can i count how many numbers enterd by the user so the output would be like this Total number of Scores = .... this is my code :- (adsbygoogle = window.adsbygoogle || []).push
What is VPN and why do I need it?
Understanding VPN - What is VPN and why do I need it? VPN is also known... decided to open another branch in the UK and there is a need to extend the same... Connecting to remote server If you are working for a company and there is a need
I need Oracle connector jar file. where will i download?
I need Oracle connector jar file. where will i download?  I need Oracle connector jar file. where will i download
regular expression expalanation i need
regular expression expalanation i need  hi......... here is my code could explain it <html> <script language = "Javascript"> function checkEmail() { if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test
What can I create with Python?
What can I create with Python?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: What can... that I can learn the topic "What can I create with Python?". Also tell
Do I need math for data science?
Do I need math for data science?  Hi, I am beginner in Data Science... so that I can learn the topic "Do I need math for data science?"...: What is Data Science? Why we need data science? What are the skills
Dear Sir I need to join u
Dear Sir I need to join u  Dear Sir i am santosh Rai from Saudi Arabia please make me understood how to join u and i have one question i want to working with you what is ur process for working with u please send me
I need your help - Java Beginners
I need your help  What is the purpose of garbage collection in Java, and when is it used?  Hi check out this url : http://www.artima.com/insidejvm/ed2/gc.html http://java.sun.com/javase/technologies/hotspot
i need the source code to generate id in jsp
i need the source code to generate id in jsp  hai,i need the source code for generate id...which is i need to generate the new id from the maximum+1,like automatically when i click the button...as well i have several kinds
i need a java code for finding typemismatch in an editor.
i need a java code for finding typemismatch in an editor.  hi im sriram, i need a java code in such a way that typemismatch code is embedded with the simple java editor. the sample output is shown below !alt text
I need add my java program with a picture.
I need add my java program with a picture.  Good evng Frnds Friends i created 1 jar file in my desktop. I need add this program with 1 picture... of opening Picture. I think most of the softwares are like that . They are first
What skills do you need for big data?
What skills do you need for big data?  Hi, I am beginner in Data...: What skills do you need for big data? Try to provide me good examples or tutorials links so that I can learn the topic "What skills do you need for big
i need a quick response about array and string...
i need a quick response about array and string...  how can i make a dictionary type using array code in java where i will type the word then the meaning will appear..please help me..urgent
I need web developer to upgrade my website
I need web developer to upgrade my website  Hi, I have a website and it is to be upgraded to HTML5 responsive website. I need web developer to upgrade my website. My website is wordpress website and developer should be able
pls i need help with my assignment
pls i need help with my assignment  how to write a code that ask the user for the height of the triangle and prints the triangle using * eg if height is 3 it prints * and also using import java.util.Scanner
PLZ HELP ME. i need php code.
PLZ HELP ME. i need php code.   I want php code for bellow OUTPUT. output is just example but it must be letters only. abc bcd efg jku rgt azs hje qqc wws adt
I need hibernate session factory example.
I need hibernate session factory example.  Hi, I want a simple hibernate session factory example..   hello, Here is a simple Hibernate SessionFactory Example Also go through the Hibernate 4 Thanks
How to find the exact PHP template I need?
How to find the exact PHP template I need?  Hi! I'm a PHP Pro?I think I am one?, but this is the first time for me to try a PHP template, so I have... I am seeking for? thx Wallace
i need some help in understanding the following codes.thanks..
i need some help in understanding the following codes.thanks..  this code is to perform LocalColorHistogram.But i can't understand it public... * height; int i = 0; int j = 0; int k = 0; double
I need help in doing this. - Java Beginners
I need help in doing this.  Student DataBase i will need creating... and their methods as needed. What program should do (Tasks): i) Read data in from..., and the student's GPA.using arrays and objects, need to structure the information
i need to answer this Question but i can't do it probably
i need to answer this Question but i can't do it probably   use the web to locate the lyrics to the traditional song"The Twelve Days of Christmas" the song contains a list of gifts received for the holiday.the list is cumulative
i need your help - Java Interview Questions
i need your help  Write a java program that: i. Allows user to enter 2 numbers from the keyboard ii. Uses a method to compare the two numbers to determine which is larger iii. Print to the screen stating which number is larger
What you need to know about Docker
What you need to know about Docker  Hi, I just came across to Docker... with separate work space. What you need to know about Docker? Explain me... in Docker container. What you need to know about Docker? Docker is a container
need help pleaseee....i weak in java
need help pleaseee....i weak in java  QUESTION 1 You are required to write an application called Customer Billing System. This system...) Separate them as either R/r for Residential or I/i for Industrial. You can use
I need your help - Java Beginners
I need your help  For this one I need to create delivery class for a delivery service .however, this class should contain (delivery number which contains eight digits. The first four digits represent the year; the last four
What classes should I take if I want to become a data scientist?
What classes should I take if I want to become a data scientist?  Hi... for the tutorials to learn: What classes should I take if I want to become a data... learn the topic "What classes should I take if I want to become a data
What should I learn before big data?
What should I learn before big data?  Hi, I am beginner in Data...: What should I learn before big data? Try to provide me good examples or tutorials links so that I can learn the topic "What should I learn before big data
What should I learn Hadoop or spark?
What should I learn Hadoop or spark?  Hi, I am beginner in Data...: What should I learn Hadoop or spark? Try to provide me good examples or tutorials links so that I can learn the topic "What should I learn Hadoop or spark

Ads