How to read from one file and write into another file?

Hi,
I am trying to read a File and write into another file.This is the code that i am using.But what happens is last line is only getting written..How to resolve this.the code is as follows,
public String get() {
     FileReader fr;
     try {
          fr = new FileReader(f);
          String str;
          BufferedReader br = new BufferedReader(fr);
          try {
               while((str= br.readLine())!=null){
               generate=str;     
          } catch (IOException e1) {
               e1.printStackTrace();
          } }catch (FileNotFoundException e) {
               e.printStackTrace();
     return generate;
where generate is a string declared globally.
how to go about it?
Thanks for your reply in advance

If you want to copy files as fast as possible, without processing them (as the DOS "copy" or the Unix "cp" command), you can try the java.nio.channels package.
import java.nio.*;
import java.nio.channels.*;
import java.io.*;
import java.util.*;
import java.text.*;
class Kopy {
     * @param args [0] = source filename
     *        args [1] = destination filename
    public static void main(String[] args) throws Exception {
        if (args.length != 2) {
            System.err.println ("Syntax: java -cp . Kopy source destination");
            System.exit(1);
        File in = new File(args[0]);
        long fileLength = in.length();
        long t = System.currentTimeMillis();
        FileInputStream fis = new FileInputStream (in);
        FileOutputStream fos = new FileOutputStream (args[1]);
        FileChannel fci = fis.getChannel();
        FileChannel fco = fos.getChannel();
        fco.transferFrom(fci, 0, fileLength);
        fis.close();
        fos.close();
        t = System.currentTimeMillis() - t;
        NumberFormat nf = new DecimalFormat("#,##0.00");
        System.out.print (nf.format(fileLength/1024.0) + "kB copied");
        if (t > 0) {
            System.out.println (" in " + t + "ms: " + nf.format(fileLength / 1.024 / t) + " kB/s");
}

Similar Messages

  • How do I read from one table and write to another identical table?

    I am very new to Oracle. I am trying to do something that should be very simple.
    I am trying to read from one table in SQL and then write to another
    Identically formatted table. I keep getting various errors. Could someone please
    post some vey simple code that will work so that I can play around with it?
    Any help would be greatly appreciated.
    Thanks,
    Ron

    Thanks, but I must be missing something.
    I have two tables, SONGLIST and SETLIST.
    The second line by itself works just fine on either table.
    Here is the code I used following your seggestion, along with it's error message.
    Hope you can help. Thanks again...
    INSERT INTO SETLIST
    SELECT TITLE FROM SONGLIST WHERE ROTATION <> 'X'
    ORA-00947: not enough values

  • How to get the data from one table and insert into another table

    Hi,
    We have requirement to build OA page with the data needs to be populated from one table and on save data into another table.
    For the above requirement what the best way to implement in OAF.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    Thanks

    You can achieve this in many different ways, one is
    1. Create another VO based on the EO which is based on the dest table.
    2. At save, copy the contents of the source VO into the dest VO (see copy routine in dev guide).
    3. commiting the transaction will push the data into the dest table on which the dest VO is based.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    if by table you mean a DB table, then no, you can have a VO based on multiple EOs which will do DMLs accordingly.Thanks
    Tapash

  • How to read LONG RAW data from one  table and insert into another table

    Hello EVERYBODY
    I have a table called sound with the following attributes. in the music attribute i have stored some messages in the different language like hindi, english etc. i want to concatinate all hindi messages and store in the another table with only one attribute of type LONG RAW.and this attribute is attached with the sound item.
    when i click the play button of sound item the all the messages recorded in hindi will play one by one automatically. for that i'm doing the following.
    i have written the following when button pressed trigger which will concatinate all the messages of any selected language from the sound table, and store in another table called temp.
    and then sound will be played from the temp table.
    declare
         tmp sound.music%type;
         temp1 sound.music%type;
         item_id ITEM;
    cursor c1
    is select music
    from sound
    where lang=:LIST10;
    begin
         open c1;
         loop
              fetch c1 into tmp; //THIS LINE GENERATES THE ERROR
              temp1:=temp1||tmp;
              exit when c1%notfound;
         end loop;
    CLOSE C1;
    insert into temp values(temp1);
    item_id:=Find_Item('Music');
    go_item('music');
    play_sound(item_id);
    end;
    but when i'm clicking the button it generates the following error.
    WHEN-BUTTON-PRESSED TRIGGER RAISED UNHANDLED EXCEPTION ORA-06502.
    ORA-06502: PL/SQL: numeric or value error
    SQL> desc sound;
    Name Null? Type
    SL_NO NUMBER(2)
    MUSIC LONG RAW
    LANG CHAR(10)
    IF MY PROCESS TO SOLVE THE ABOVE PROBLEM IS OK THEN PLESE TELL ME THE SOLUTION FOR THE ERROR. OTHER WISE PLEASE SUGGEST ME,IF ANY OTHER WAY IS THERE TO SOLVE THE ABOVE PROBLEM.
    THANKS IN ADVANCE.
    D. Prasad

    You can achieve this in many different ways, one is
    1. Create another VO based on the EO which is based on the dest table.
    2. At save, copy the contents of the source VO into the dest VO (see copy routine in dev guide).
    3. commiting the transaction will push the data into the dest table on which the dest VO is based.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    if by table you mean a DB table, then no, you can have a VO based on multiple EOs which will do DMLs accordingly.Thanks
    Tapash

  • Copying from one arrangement and pasting into another arrangement

    Hi, I'm using Logic Express 8.
    I'm wondering if there is a way to copy several tracks from one arrangement window into another. I've tried to do this simply by copying and pasting, but when I paste into the new arrangement window I get error messages and the tracks pasted into the new window have a speaker icon with an "X" through it - and obviously no sound.
    Am I missing something, or perhaps this is simply a limitation that exists with using express instead of pro?
    Thanks a lot.

    You can do this by simply importing the data from one project to your new one. Check it out here.

  • Export from one version and import into another version

    We have a customer database that accidently got updated to 10.2.x but our application only supports 10.1.5 What we are wondering can we export the 10.2 database and import it into a new system that is at our supported version of 10.1.0.5?
    Will the import even work or will it fail with unsupported version? Any other things we should be aware of?

    ro**** wrote:
    We have a customer database that accidently got updated to 10.2.x but our application only supports 10.1.5 What we are wondering can we export the 10.2 database and import it into a new system that is at our supported version of 10.1.0.5?
    Will the import even work or will it fail with unsupported version? Any other things we should be aware of?between versions export MUST ALWAYS be done with lowest version of export utility!

  • How to read XML file and write into another XML file

    Hi all, I am new to JAVAXML.
    My problem is I have to read one XML file and take some Nodes from that and write these nodes into another XML file...
    I solved, how to read XML file
    But I don't know how to Write nodes into another XML.
    Can anyone help in this???
    Thanks in advance..

    This was answered a bit ago. There was a thread called "XML Mergine" that started on Sept 14th. It has a lot of information about what it takes to copy nodes from one XML Document object into another.
    Dave Patterson

  • How do I move all my files from one User Profile (account) into another? I needed to create a new account and want all of my files accessible in the new one.

    How do I move all my files from one User Profile (account) into another?
    I needed to create a new account and want all of my files accessible in the new one.

    ok, what you're learning right now is 101 unix, which is good. Unix is a good thing
    now: the way unix works, and macos (which uses unix underneath) the files and folders work like a hierarchy.
    the start of that tree is /
    so, if you were to do:
    cd /
    (cd means change directory)
    it will bring you at the highest branch of the file system.
    cd /Users
    will bring you to where all the users are.
    to see whats in /Users you can use your friend ls command
    ls means list files/directories
    so:
    cd /Users
    ls -la
    (the -la here means show all (even hidden) and long format (very verbose))  this flag is very optional.
    you will see
    fred
    user2
    for example.
    if you want to see the desktop of user2 you would change directory to it then list the files.
    for example:
    cd /Users/user2/Desktop
    Note that the files and directory are case sensitive, so, desktop is NOT the same as Desktop, or DESKTOP
    ls -la
    you should then be able to see everything in users2 desktop
    you could have done as well the same thing in smaller steps, for example:
    cd /
    cd Users
    cd user2
    cd Desktop
    this is the equivalent of cd /Users/user2/Desktop
    So, for your file, i don't know where it was, but know that if you log in as user2, it will directly put you in
    /Users/user2
    which most likely the file you had created from the other user was in /Users/user1
    if you copied all the files from /Users/original_user to /Users/secondUser
    most likely yes, all your mail, bookmarks etc would be copied over.
    so in your case.
    sudo chown -R seconduser:staff /Users/secondUser
    should work
    Remember that if you start a path with the character /  it means start from the root of the file system, at the highest top you can ever get.
    so
    cd /Users/fred
    is not the same as
    cd Users/fred
    unless you were in / already
    i know it may be confusing at first but it's actually very logical if you play with it.
    to simplify, think of it that / means C:\  on windows
    you can't go any higher than C:\  (in a way)
    if you're unsure which directory you're currently in, you can always type:
    pwd
    it will tell you where you are.
    for example:
    cd /
    pwd
    this shows  /
    cd Users
    pwd
    this now shows /Users
    cd /System/Library
    pwd will show /System/Library
    cd /
    cd /Users
    cd fred
    cd Library
    pwd will show /Users/fred/Library
    unix can look very scary but it's actually vital and very necessary to do tasks sometimes that would take for ever to do via the windows. This is good learning.
    so for the myfile you had created, i can't tell you where it is, at the time you created, if you can do a pwd command you'll know the path,
    ls -la  (this shows all the files where you are)
    if you see myfile in the list
    do a pwd
    whatever is return, the real location of the file would be:
    whatever pwd returned / myfile
    I hope that makes sense.

  • How to read from properties file

    Hi,
    I am using JSR 168.
    while creating a new portlet, a folder gets created with the name as "portlet". Under which is resource package and <PortletName>Bundle.java.
    pls tell me how to read from .properties file.
    waiting eagerly for some reply
    Thanks & Regards,
    HP
    Edited by: user9003827 on Apr 13, 2010 3:42 AM

    I think i have mixed it up :)
    I have looked at it again and believe you are using regular JSP portlets.
    Can you tell what you want to achieve by reading .properties file. Are you meaning the preferences of the portlet or what exactly are you trying to do?
    Reading propertie files is easy:
    // Read properties file.
    Properties properties = new Properties();
    try {
        properties.load(new FileInputStream("filename.properties"));
        String myKey = properties.getProperty("yourKey");
    } catch (IOException e) {
    }Edited by: Yannick.O on 13-Apr-2010 05:52

  • How to read from pdf file using VB

    I have a PDF file which contains three columns, emp no, designation, contact_info. I have 10 rows in that pdf file. I want to read row by row from the pdf file and write into another text file(tab delimited) using VB.
    Could you please help me reading the pdf file?
    Thanks,
    Arindam

    Without reading it in detail, this seems to be automating a save as text function in Acrobat. This will not give you any position information.
    If you want position information without writing a plug-in, you need to use the getPageNthWord and getPageNthWordQuads methods in JavaScript.
    If you have not already done so, you will need to download the Acrobat SDK which has the documentation you need.
    Writing in C# makes even very simple things complicated; if you have a choice, consider VB.

  • How do you take pictures from one library and put in another library??

    How do you take pictures from one library and put in another library??

    Options:
    1. Export from iPhoto A to the Finder, then import to iPhoto B
    This gets the photo over, but no versions, no edit history and not all the metadata
    2. Use iPhoto Library Manager
    This gets everything: versions, edit history and all the metadata.
    Regards
    TD

  • Read from one file ... and write

    I had written below code to read from a file
    which has input in below format...
    $ filla
    % dillla
    I wrote a code to read from the below file and I want to write into another file...
    in another format...like
    filla, $
    dilla, %
    I wrote as below... but my code doesn't work....i commented most of the code becoz I doubt ....
    I read the file...line by line...
    each line has two words one is special characters($ or %) and the other is some name... separated by space..
    I stored both in different arrays...and thought to write them in output file...
    import java.io.*;
    public class data
           public static void main(String args[])
                int kMaxLines = 60000;            
                  String[][] valuePairs = new String[2][kMaxLines];
                  String symbol [] = new String[kMaxLines];
               String name [] = new String[kMaxLines];
               int k = 0;
                       try            
                      FileInputStream fstream = new FileInputStream("c:/inputs.txt");
                      DataInputStream datastream = new DataInputStream(fstream);
                      BufferedReader br = new BufferedReader(new InputStreamReader(datastream));
                      //FileWriter output = new FileWriter("c:/output.txt");
                 //BufferedWriter bw = new BufferedWriter(output);
                      String names; 
                      String strLine;
                      int line = 0;
                      while ((strLine = br.readLine()) != null)
                           String temp_strs[] = strLine.split(" ");
                          for (int j = 0; j < 2; j++)
                          valuePairs[j][line] = temp_strs[j];
                         //System.out.println(temp_strs[0] + " " + temp_strs[1]);
                          symbol[k]= temp_strs[0];  
                          name[k]=temp_strs[1];
                          line++;
                          k++;
                      for (k=0; k < kMaxLines; k ++)
                      System.out.println(symbol[k]+ "" + name[k]); // when I print it is giving null value...
                      } // so what I do to get those values into global array...
                          datastream.close();
                // to write to file
                   //String names_str;
                        //bw.write("@relation train");
                  //for(k=0; k<kMaxLines; k++)
                    //  names_str = names+""+name[k];
                   //bw.write("@attribute names" + " {"+names_str+"}");
                   //bw.write("@attribute class {+,-}");
                   //bw.write("@data"+"\n");
                    // for (k=0;k<kMaxLines; k++)
                   //bw.write("name[k]+","+symbol[k]");
                       catch (Exception e)
                      //file not found exception...
                            e.printStackTrace();
     

    Why the multiple arrays?
    I'd just read it into List<String[]>... an extensible collection of "the fields on each line"... then you just write them out as required.
        second-field + comma + first-field.
    I suggest your next move should be to take a backup copy of your current class then rip-all that commented-out code out of it, and reformat it properly... starting from a clean(er) slate... then try swapping over to a List<String[]> instead of that cumbersome String[][] matrix.
    Try that... if you get stuckeroonied then don't be afraid to ask again.
    Cheers. Keith.

  • How to  read from excel file and write it using implicit jsp out object

    our code is as below:Please give us proper solution.
    we are reading from Excel file and writing in dynamicaly generated Excel file.it is writing but not as original excel sheet.we are using response.setContentType and response.setHeader for generating pop up for saveing the original file in to dynamically generated Excel file.
    <%@ page contentType="application/vnd.ms-excel" %>
    <%     
         //String dLoadFile = (String)request.getParameter("jspname1");
         String dLoadFile = "c:/purge_trns_nav.xls" ;
         File f = new File(dLoadFile);
         //set the content type(can be excel/word/powerpoint etc..)
         response.setContentType ("application/msexcel");
         //get the file name
         String name = f.getName().substring(f.getName().lastIndexOf("/") + 1,f.getName().length());
         //set the header and also the Name by which user will be prompted to save
         response.setHeader ("Content-Disposition", "attachment;     filename="+name);
         //OPen an input stream to the file and post the file contents thru the
         //servlet output stream to the client m/c
              FileInputStream in = new FileInputStream(f);
              //ServletOutputStream outs = response.getOutputStream();
              int bit = 10;
              int i = 0;
              try {
                        while (bit >= 0) {
                        bit = in.read();
                        out.write(bit) ;
    } catch (IOException ioe) { ioe.printStackTrace(System.out); }
              out.flush();
    out.close();
    in.close();     
    %>

    If you want to copy files as fast as possible, without processing them (as the DOS "copy" or the Unix "cp" command), you can try the java.nio.channels package.
    import java.nio.*;
    import java.nio.channels.*;
    import java.io.*;
    import java.util.*;
    import java.text.*;
    class Kopy {
         * @param args [0] = source filename
         *        args [1] = destination filename
        public static void main(String[] args) throws Exception {
            if (args.length != 2) {
                System.err.println ("Syntax: java -cp . Kopy source destination");
                System.exit(1);
            File in = new File(args[0]);
            long fileLength = in.length();
            long t = System.currentTimeMillis();
            FileInputStream fis = new FileInputStream (in);
            FileOutputStream fos = new FileOutputStream (args[1]);
            FileChannel fci = fis.getChannel();
            FileChannel fco = fos.getChannel();
            fco.transferFrom(fci, 0, fileLength);
            fis.close();
            fos.close();
            t = System.currentTimeMillis() - t;
            NumberFormat nf = new DecimalFormat("#,##0.00");
            System.out.print (nf.format(fileLength/1024.0) + "kB copied");
            if (t > 0) {
                System.out.println (" in " + t + "ms: " + nf.format(fileLength / 1.024 / t) + " kB/s");
    }

  • How to read from a file line by line

    Hi
    I am new to using LabView and was wondering how I could read data from a text file one line at a time and display this data one line at a time as well. I tried looking through the Reading from Text File . vi example but that just seems to be reading and displaying everything together.
    Thanks
    -Karan

    Hi
    My aim is to read text line by line and to then go ahead and display the last 8 reaad lines of code to give the impression of text falling down a screen. I tested the first while loop and that seemed to work fine. However, when I encounter an EOF, I would like the text already read to keep making its way down the screen and keep inputting NULL characters into the array to simulate the effect of the text falling down the screen which is why I created the second while loop. I tried to input the NULL characters using a box for ENUM constants. However, I kept getting an error saying the data types do not match. What would I need to do? For the display I plan on putting indicators next to the 8 places where the text would be stored which I have not done so far.
    I am also attaching a copy of the error.
    Thanks
    -Karan
    Attachments:
    DisplayText.vi ‏40 KB
    Error.JPG ‏89 KB
    PictureOfBlock.JPG ‏120 KB

  • How to read from text file?

    I would like to read data (frequencies) already written in a text file. I will need read these frequencies one at a time to set the function generator (as part of my data acquisition application), acquire data that is in turn written to a file and then go back and read the next frequency from the file to repeat the process again. I also have another idea of doing the same, which is read all the frequencies from the text file and populate a table and a frequency value is picked from the table each time to go through the process mentioned above.
    Can anyone suggest the following: (1) How to read from a text file, (2) What could be the most efficient way of solving my above problem.
    I am a new LabVIEW user and any help will be appreciated.

    Hi Research,
    Depending on the format of the data file, there are a few options for reading it.  If it is tab delimited, you may want to use the Read from SpreadSheet File VI which will read the file into an Array.  You can then use the Index Array VI to pull out individual entries.  If the files is ASCII but not tab delimited, you could use the regular Open File and Read File VIs.  You can either read the file out piece by piece, or read the entire file into a string and then use the Match Pattern VI to parse out the different elements (there are actually many ways to do this - check out the Strings subpalette). 
    Since you're new to LabVIEW, you may want to check out these resources:
    Three Hour Introduction to LabVIEW
    Six Hour Introduction to LabVIEW
    Getting Started with LabVIEW
    I hope this helps!  Let us know if you have more questions,
    Megan B.
    National Instruments

Maybe you are looking for