Read multiple files and write data on a single  file in java

Hello,
I am facing difficulty that I want to read multiple files in java and write their data to a single file. Means Write data in one file from multiple files in java
Please help me out.
Naveed.

algorithm should be something like:
File uniqueFile = new File();
for (File f : manyFilesToRead)
   while (readingF)
       write(dataFromF, intoUniqueFile);

Similar Messages

  • Create xml file and write data in to it:

    Hi All,
    I have a small requirement here.....
    I have a java program which reads a xml file.
    Now i have stored the contents of that file in to a java object.
    I want a sample code now which would take theabove mentioned java object as an input ,create a xml file and write these entries in to the file.
    Can anyone help me in this?
    Your help would be appreciated.
    Thanks in advance.
    vrkr

    Hmmm. There is nothing special about an XML file to any other file. The data is simply formatted in a certain way. So to write an XML file, it is no different to writing any other form of file in Java (assuming you know the structure of the xml format to write - which you should)
    If you don't know how to write files using Java I would suggest using the Java Tutorial found on java.sun.com and do some reading up about I/O since this is fairly fundamental.
    http://java.sun.com/docs/books/tutorial/
    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • How can FMS create a text file and write data into it in the Server application folders?

    Recently, I writed a programe about creating a text file and writing data into it in the server application folder. My code is as following:
               var fileObj = new File("/MyApp/test.txt");
               if( fileObj !=  null)
                      if(fileObj.open( "text", "append"))
                            fileObj.write( "                                                      ———— Chat Info Backup ————\r\n" );
                            fileObj.close( );
                            trace("Chat info backup document :" +  fileObj.name + " has been created successfully!");    
    But when I run it, FMS throw the error as following: File operation open failed  ;  TypeError: fileObj has no properties.
    Can you help me ? Thanks in advance.
    Supplement: The text file named test.txt doesn't exist before create the fileObj, an instance of File Class.

    Is MyApp the name of the application directory, or is it a child of the application directory? If myApp is the app name, just use test.txt as the path flag in the file constructor.

  • How to activate another worksheet in excel file and write data into it

    Hi,
    I am writing an automation program to collect test data and write the data to an excel file.
    The excel file has several worksheets and now I can only write data to one sheet. Can anyone please let me know how to activate another worksheet and write data into it? Thank you very much.

    You can do a search in the Example Finder for more Excel VIs.
    They will give you a clearer idea of how to go about doing things in the way you need.
    - Partha
    LabVIEW - Wires that catch bugs!

  • Using cfhttp to read a page and write its contents to a file.

    Hi,
    I am trying to get a feed of my ebay store listings to load
    into froogle. Unfortunately, ebay provides the feed as a website
    not a file and froogle (via GoogleBase) needs the file to be
    submitted as an XML file.
    Is there a way to use something like cfhttp to load up the
    page where the feed is located, scan the page and write it's
    contents into an XML file that I can then load up to GoogleBase???
    thanks for the help.

    ignore me now.... I answered my own question a short while
    ago.
    for anyone who cares....
    I used CFHTTP to get the page and then used a cffile to write
    the #cfhttp.filecontent# into the new file!

  • Read a doc file and write back to a doc file

    How to read line by line from a doc file and then arrange it.
    Like-->
    amit
    sumit
    prem
    jeev
    these four names are present in the doc file. Now how to read by means of java program and sort these names and write back to a new doc file?????
    What packages and methods are to be used??
    Please help.....
    Edited by: Jaguar on Apr 11, 2011 12:16 AM

    Jaguar wrote:
    How to read line by line from a doc file and then arrange it.By 'doc' do you mean MS Word?
    these four names are present in the doc file. Now how to read by means of java program and sort these names and write back to a new doc file?????You seem to have a sticky '?' key and an unreliable shift key (to apply an upper case letter to the start of every sentence). Please fix them.

  • How to open an Excel file and write data into it.

    Hi All,
    I have an excel template, which has graphs and some tables containing corresponding data. If i change the data in tables it changes the graphs. So, if i have a template in the server, is it possible for me to open this excel file and change the data in the tables to chanage the graphs. How can i go to different worksheets and go to different cells and change the values and save the file.
    Thanx in advance
    Cheers
    Pej

    You can setup an ODBC connection to the Excel file and update the file with JDBC, using the JDBC-ODBC bridge.
    Hope this helps

  • Comparing an excel file to and xml file and appending data to the xml file

    I have an xml file (mapsource) and an excel file. One of the columns in the excel file matches up with a node in the xml file. I want to be able to loop through both files and add a new node to the xml file where the one of the columns in the excel file matches a node in the xml file.
    I can create a query object out of the excel dosument using the cfspreadsheet tag.
    I'm able to use xmlparse to create a xml document object from the xml file.
    What I would like to do is add col_3 from the excel spreadsheet as a new node when col_2 is equal to gpx.wpt.name.xmltext of the xml object.
    Any help or direction would be very helpful!

    Hi,
    Thank you for your reply. But I have to attach an excel file from a particular path (C:\TEMP\TEST.XLS) and I have to send that excel file to the user inbox.That excel file has multiple sheets with data. Can you please provide me any code is available.
    Thanks and Regards
    venkat.

  • Read a bfile and write its contents in a file stored in my hard disk

    I will try to describe my problem as clearly as I can.
    I have created a table that includes a LOB column "BFILE"
    Then I'm trying to READ the BFILE stored in our database using the
    DBMS_LOB package.
    so far so good.
    Now I want to write these data that I have read in the step above in a file
    saved in my local disk. The problem is, since the file in databse is
    stored as binary and I read Raw Data , I cannot create an exact copy of this
    file. It seems that It doesn't write the RAW data in the binary format.
    I have used the DBMS_LOB.READ to read the data and it works fine.
    Now I want to create a file in my local disk and dump the data that I have
    read from the BFILE that has been initially stored in the database.
    Is there any solution to this problem?
    I hope to hear from you soon
    Thanks in advance

    ignore me now.... I answered my own question a short while
    ago.
    for anyone who cares....
    I used CFHTTP to get the page and then used a cffile to write
    the #cfhttp.filecontent# into the new file!

  • Reading multiple text files and writing them to one text file

    Hi,
    I'm trying to read a number of text files and write them to a single master file. My program reads all the files but only writes the last one to the master file.
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    // Input/Output Classes
    import java.util.Scanner;
    import java.io.PrintWriter;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.FileNotFoundException;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    import javax.swing.JTextArea;
    import java.awt.GridLayout;
    public class Actor implements ActionListener
    public static String DataRoot = "I:\\JAVA\\UBP\\DAT
    public static JFrame SW = new JFrame();
    public static JTextField txtSPath;
    public static JTextArea txtTable;
    public void actionPerformed( ActionEvent e )
    String Command = e.getActionCommand();
    if (Command.equals("Process") )
    SetupWin();
    ProcessAll();
    public void SetupWin()
    SW.setTitle("void");
    SW.setSize(300,400);
    SW.setLayout(new GridLayout(6,1));
    txtSPath = new JTextField(40);    SW.add(txtSPath);
    txtTable = new JTextArea(10, 40); SW.add(txtTable);
    SW.setVisible(true);
    public void ProcessAll()
    Process("Dunstable","Finance");
    Process("Dunstable","Production");
    Process("Dunstable","Sales");
    public void Process(String Town, String Dept)
    String SPath = DataRoot + Town + "
    " + Dept + ".txt";
    String MPath = DataRoot + "masterFile" + ".txt";
    txtSPath.setText(SPath);
    String message = "Trying  " + SPath;
    System.out.println(message);
    String SlaveTable=message;
    try// if following fails an exception is thrown
    Scanner Slave = new Scanner(new FileInputStream(SPath)); // reads slave file
    PrintWriter outputStream = null;
    outputStream = new PrintWriter(new FileOutputStream(MPath));
    while ( Slave.hasNextLine() ) // reads text line by line
    //Read and output next record
    String PartRecord  = Slave.nextLine();
    String FullRecord = Town + " " + PartRecord;
    System.out.println(FullRecord);
    outputStream.println(FullRecord);
    Slave.close();
    outputStream.close();
    txtTable.setText(SlaveTable);
    //An Exception Error would be THROWN by above & CAUGHT below
    catch(FileNotFoundException e)
    message = "Could Not Find " + SPath;
    System.out.println(message);     //console
    txtSPath.setText(message);     //window
    catch(IOException e)
    System.out.println("Slave I/O Problem " + SPath);
    }Edited by: Ardour on Mar 4, 2008 1:53 PM

    I haven't looked closely, but my spidey sense tingles at this:
    new FileOutputStream(MPath)This will clobber (erase) the previous contents of the file. Open in append mode:
    new FileOutputStream(MPath, true)Of course, if the file exists before you run this code, you will end up append to the original contents. If that is not wanted, consider using File's delete method first.

  • Trying to write data to a text file using java.io.File

    I am trying to create a text file and write data to it by using java.io.File and . I am using JDeveloper 10.1.3.2.0. When I try run the program I get a java.lang.NullPointerException error. Here is the snippet of code that I believe is calling the class that's causing the problem:
    String fpath = "/test.html";
    FileOutputStream out = new FileOutputStream(fpath);
    PrintStream pout = new PrintStream(out);
    Do I need to add additional locations for source files or am I doing something wrong? Any suggestions would be appreciated.
    Thank you.

    Hi dhartle,
    May be that can help:
    * Class assuming handling logs and connections to the Oracle database
    * @author Fabre tristan
    * @version 1.0 03/12/07
    public class Log {
        private String fileName;
         * Constructor for the log
        public Log(String name) {
            fileName = name;
         * Write a new line into a log from the line passed as parameter and the system date
         * @param   line    The line to write into the log
        public void lineWriter(String line) {
            try {
                FileWriter f = new FileWriter(fileName, true);
                BufferedWriter bf = new BufferedWriter(f);
                Calendar c = Calendar.getInstance();
                Date now = c.getTime();
                String dateLog =
                    DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM,
                                                   Locale.FRANCE).format(now);
                bf.write("[" + dateLog + "] :" + line);
                bf.newLine();
                bf.close();
            } catch (IOException e) {
                System.out.println(e.getMessage());
         * Write a new line into a log from the line passed as parameter,
         * an header and the system date
         * @param   header  The header to write into the log
         * @param   info    The line to write into the log
        public void lineWriter(String header, String info) {
            lineWriter(header + " > " + info);
         * Write a new long number as line into a log from the line 
         * passed as parameter, an header and the system date
         * @param   header  The header to write into the log
         * @param   info    The line to write into the log
        public void lineWriter(String header, Long info) {
            lineWriter(header + " > " + info);
         * Enable to create folders needed to correspond with the path proposed
         * @param   location    The path into which writing the log
         * @param   name        The name for the new log
         * @return  Log         Return a new log corresponding to the proposed location
        public static Log myLogCreation(String location, String name) {
            boolean exists = (new File(location)).exists();
            if (!exists) {
                (new File(location)).mkdirs();
            Log myLog = new Log(location + name);
            return myLog;
         * Enable to create the connection to the DB
         * @return  Connection  Return a new connection to the Oracle database
        public static Connection oracleConnectionCreation() throws Exception {
            // Register the Oracle JDBC driver
            DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
            //connecting to the DB
            Connection conn =
                DriverManager.getConnection("jdbc:oracle:thin:@myComputerIP:1521:myDB","user", "password");
            return conn;
         * This main is used for testing purposes
        public static void main(String[] args) {
            Log myLog =
                Log.myLogCreation("c:/Migration Logs/", "Test_LinksToMethod.log");
            String directory = "E:\\Blob\\Enalapril_LC-MS%MS_MS%MS_Solid Phase Extraction_Plasma_Enalaprilat_ERROR_BLOB_test";
            myLog.lineWriter(directory);
            System.out.println(directory);
    [pre]
    This class contained some other functions i've deleted, but i think it still works.
    That enables to create a log (.txt file) that you can fill line by line.
    Each line start by the current system date. This class was used in swing application, but could work in a web app.
    Regards,
    Tif                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Find a string in a file and write a new text after it

    hi
    i try to search a string in a small text file. after this position I should write a new text (it is not the end of the text, it could be somewhere between).
    I tried to solve this with the StrginTokenizer, but it does not work properly, any other ideas how to solve this?
    thanks for your comments
    steinfresser

    To insert text into the middle of a file you use the process that has been used since the first text editor was invented over 50 years ago:
    1. Read the text from the file up to the insert point, and write it to a new file.
    2. Write the inserted text to the new file.
    3. Read the rest of the text from the file, and write it to the new file.
    4. Delete the file.
    5. Rename the new file.

  • How to read and write data in to a specified range of cells(it include multiple row & columns) in excel

    How to read and write data in to a specified range of cells(it include multiple row & columns) in excel

    CVI Comes with a sample project that explains how to read/write to a Excel file: choose "Explore examples..." in CVI welcome page and navigate to <cviSampleDir>\activex\excel folder where you can load excel2000dem.prj.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Read the file and write the data into string or int

    Ok, here's another rookie question.
    I got to read the line from the file and store it in the memory as string or integer.
    I wrote this code:
    File inputFile = new File("c:/xxx.yyy");
    String outputString = new String();
    FileReader c1 = new FileReader(inputFile);
    StringWriter d1 = new StringWriter(outputString);
    int data;
             while((data = c1.read()) != -1)
                 d1.write(data);
                 System.out.println(data);
             c1.close();
             d1.close();This is how I see it, but it cannot be even compiled because there is no such thing as StringWriter(String) wich I find completely irrational. So tell me, am I retarded or what? No, but seriosly, please help the newbie to understand these streams, am I supposed to use some kind of buffer? Any help appreciated.

    A String is an immutable. You cannot update a String.
    A new String() is basically the same as an empty String ""
    An empty StringWriter can be created with new StringWriter().
    If you use a BufferedReader you can call readLine().
    BufferedReader in = new BufferedReader(new FileReader(filename));
    String line;
    while((line = in.readLine()) != null) {
      System.out.println(line);
    }

  • Reading Data from Unix file and write into an Internal table

    Dear all,
                     I am having an requirement of reading data from unix file and write the same into an internal table..how to do that ...experts please help me in this regard.

    Hi,
    do like this
    PARAMETERS: p_unix LIKE rlgrap-filename OBLIGATORY.
    DATA: v_buffer(2047) TYPE c.
    DATA: BEGIN OF i_buffer OCCURS 0,
            line(2047) TYPE c,
    END OF i_buffer.
    * Open the unix file..
    OPEN DATASET p_unix FOR INPUT IN TEXT MODE.
    <b>IF sy-subrc NE 0.
    *** Error Message "Unable to open file.
    ELSE.</b>
       DO.
         CLEAR: v_buffer.
         READ DATASET p_unix INTO v_buffer.
         IF sy-subrc NE 0.
            EXIT.
         ENDIF.
         MOVE v_buffer TO i_buffer.
         APPEND i_buffer.
      ENDDO.
    ENDIF.
    CLOSE DATASET p_unix.
    <b>Reward points if it helps,</b>
    Satish

Maybe you are looking for

  • How to sort a column of type CHAR

    Hi, I have a report for which the o/p is displayed in ALV grid format.There is one column in the O/p strcuture which is "No of days".Based on certain conditions,i need to display the value for some of the days as Negative e.g. " - 45".Becasuse of thi

  • Audio feedback in web-calls

    When connecting Apple TV with AirPlay for conference call apps, the iPad sound-cancellation doesn't recognize that the sound from the Apple TV is its own. We use GoToTraining to have a conference call & when the person from the call speaks it comes t

  • WRT610N Configuration: blocking all UDP connections

     Hi all, I am the disapointed owner of the WRT610N. I previously had a buffalo N routeur in the UK, which had no firmware update in 9 months, and plenty of spelling mistakes and problems (router hanging, needed to reset). I managed to refund it and I

  • A good NAT design problem

    I have a router with two interfaces which of course have two different subnet ranges. This is going to be on a network with two possible paths to the Internet. I need to have traffic go in two possible directions. I also need to have a NAT pool so th

  • I want to cancel my annual ExportPDF subscription. Please let me know how to proceed with this as soon as possible.

    Please let me know how to cancel my annual ExportPDF subscription immediately - Adobe has made this cancellation process unnecessarily complicated.