File manipulations

File manipulations

how to read the contents from one file and move the contents to another file

View Answers

November 26, 2010 at 4:41 PM

Hi Friend,

Try the following code:

import java.io.*;
import java.util.*;

public class ReadFile{
    public static void main(String[]args)throws Exception   {
        File f=new File("data.txt");
  FileInputStream fstream = new FileInputStream(f);
   DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String str;
    FileOutputStream fos=new FileOutputStream(new File("new.txt"));
    while ((str = br.readLine()) != null)   {
    System.out.println(str);
    fos.write(str.getBytes());
    }

    fos.close();
    in.close();
    }
}

Thanks









Related Tutorials/Questions & Answers:
File manipulations
File manipulations  how to read input to a file from console
File manipulations
File manipulations  how to count number of words in a file
Advertisements
File manipulations
File manipulations  how to read the contents from one file and move the contents to another file
File
File  How to create .Exe file in jana
file
file  how can copy the information in the file to the string?   Store file data into String
file
file  Could anyone please help me to write a code that does the following: Opens a file named MyName.txt, reads the first line from the file and displays it, and then closes the file. Thank you so much
file
file  how can add the information to the graphic file
file
file  Hi,what can delet some of the information of the file
file
file  Hi,how can delet some of the information of the file
File
File   How to find all files in our local computer using java
FILE
FILE  There is a file named Name.txt that contains information related to appliances.I want to read the contents of this file and I used the code... args[]) { try { File file=new File("Name.txt"); FileReader f=new FileReader(file
file
file  hi i want read special line of file. what am i doing ? I write... read data from file. please help me! void maketree(BtNode root,int i) throws... at the following link: Read specific line from file
File path for jar file
File path for jar file  Hi Experts, I have created one eclipse... jar file of that application, unfortunately it is giving the error that resource not found for the template file. Also I had tried to get that path from user
file
EAR file
EAR file   What is the EAR file
EAR file
EAR file   What is the EAR file ?   An EAR file is a standard JAR file with an .ear extension, named from Enterprise ARchive file. A J2EE application with all of its modules is delivered in EAR file
File Operations
File Operations  Please i would like to know if it is possible to read from a file and write to the same file at the same time
WAR file
WAR file  What is a WAR file
File Transfer
File Transfer  How to create a file in server side using java swing
File Upload
File Upload  when i execute the image upload to mysql database it shows an exception that file path cannot be found
deleting file
deleting file   how to delete a file from a folder and its corresponding path in database using a servlet
File Handling
File Handling  how we do file handling of parsed XML code bu DOM in java
JSP File
JSP File  Hi, What is JSP File? How to create JSP file? Thanks   Hi, JSP file is simple text file with .jsp extenstion. You can run JSP file on tomcat server. Read more at JSP tutorials section. Thanks
JAR FILE
JAR FILE  WHAT IS JAR FILE,EXPLAIN IN DETAIL?   A JAR file... and applications. The Java Archive (JAR) file format enables to bundle multiple files into a single archive file. For more information, visit the following
on file system
on file system  how to maintains record in a file using java and how to create objects to each record.   Hi, Please read Java Write file tutorial.ADS_TO_REPLACE_1 Regards Deepak
File Upload
File Upload  Hi I need script / string in PHP where I uploaded the file in html frontend and it should sent the uploaded file as attachment to my email address
jar file
jar file  steps to create jar file with example
jar file
jar file  how to create a jar file in java
File handlig
File handlig  File hyandling   Hi Please the click on the following link Java file Handling And read the Articles given in it   Hi Please the click on the following link Java file Handling And read
FILE CONCEPT
FILE CONCEPT  Prompt the user to enter the name of a text file to search for. If the name does not end in a .txt extension, display an error message. Search for this file in the current directory. If the file does not exist print
class file
class file  How to create class file in jsf easily
jar file
jar file  jar file where it s used
file read
file read  hi i am reaing from a file which has punjabi words. can some one help with me some code
File transfer
File transfer  Hi there... I would like to know is it possible to transfer files from one directory to another with out file io operations
file download
file download  I uploaded a file and saved the path in database. Now i want to download it can u plz provide code
file searching
file searching  i need a prog for searching inside a text file after evry 1 min to find does it hav any new entry
file upload
file upload  how to recieve the uploaded file on the next jsp page for modification if its uploaded to the previous page using a from
Convesion of txt file to doc file.??????
Convesion of txt file to doc file.??????  how to convert text file to doc file using java
String file in to word file in java
String file in to word file in java  How to convert a String format notepad file into Ms word file in java
read a file
read a file  read a file byte by byte   import java.io.File..._TO_REPLACE_1 public static void main(String[] args) { File file = new File("D://Try.txt"); try { FileInputStream fin = new FileInputStream(file
Property File
Property File  how to store key & values pair in property file? Note: In property file keys should be displayed in ascending order. please reply..."); properties.setProperty("National-Bird", "Peacock"); File file = new File
file operations
file operations  everytime we run the program the data in the already file is overridding ,so,how to append the data to the already existing files .so please send the function required and also source code
jsp-file
jsp-file  i want to upload a file by browse button and the file should be save in ms access database.....how i can implement trough jsp plz help me sir
file uploading
file uploading  How to upload music files onto the server and save the file information to the mysql database fetch and play the music files on a display page without download thus streaming the files
generate file
generate file  How to generate file(.doc or .xls or .txt ) with containing data in it.By clicking on a link
jar file
jar file  how to run a java file by making it a desktop icon i need complete procedur ..through cmd
file class
file class  Hi Friend, I have a file class it lets me extract all the data from a csv file but I need to align the data properely, seperating... void ReadCSV(){ File csvFile = new File("Hotels.csv
file attach
file attach  how pick up the file from database and attach it to the mail in java   Hi, Here is the code to read image (file) from...(); } After reading the image you can save into file or attach as attachment in your
File handling
File handling  how do i search for an occurance of a word in a file... in a file import java.io.*; import java.util.*; class FileOperations{ public static void main(String[] args)throws Exception{ int count=0; File f
war file
war file  where should we create this war file in servlet program for example servlet structure like this 1.app(servlet) 2.WEB-inf(web.xml) 3.class(.class

Ads