Writing Data to Multiple Files

Hi,
I got a problem while writing the data to multiple files.
Actually my requirement is,
I want to read the data from multiple files and retrieve the required data from those and save that data into separate files.
Meaning if i read the data from "D:\kiran\kk\123\kiran.txt" the retrieved data should be saved in "D:\kiran\kk\kiran.txt" the file name should be created with the input file name.
here is my code,
//here i am taking the files into loop
for(int i=0;i<files.length;i++){
try{                   
//reading the files
BufferedReader br=new BufferedReader(new FileReader(files));
//creating a new file for writing the retrieved data
pw=new PrintWriter("D:\\Kiran\\kk"+File.separator.concat(str[i]));
String line=br.readLine();
while(line!=null){
line=br.readLine();
//here i am matching the required data
Matcher m = Pattern.compile("name(\\s*\\W*\\w*\\W*.\\w*.)|invoice (\\W*(\\d+))|amount(\\W*(\\d+),\\d*)|site(\\s*Rs\\.[\\d]*,[\\d]*/-)", Pattern.CASE_INSENSITIVE).matcher(line);
while(m.find()){                           
System.out.println(m.group());
//here printing the retrieved data to a file
pw.println(m.group());
br.close();
but i am ending up with some issues.
Data is reading properly from all the files, but when i write that data into individual files the data which is retrieved from last file is only printing into the file which is created last.
Please help me regarding this,
Thanks,
Kiran

D:\kiran\kk\123\
In this folder some files are there say,
kk.txt,kiran.txt,praveen.txt and so on, i can read the entire data from those files and also retrieving the required data like name,data etc. from all the files. Now the retrieved data should be stored in individual files means, if the data is retrieved from kk.txt then that particular data should be stored in the file with the same file name but in different location likewise it should happen for all the files those are in that folder.
Thanks,
Kiran

Similar Messages

  • Save data to multiple files

    Hi!
    I am trying to save measurement data to multiple files using the Write to measurement Express VI. The problem is that no matter what I do the program always save the data to one huge file, even if I configure the VI to save the data as a series of separate files.
    I am using LabVIEW 8.2 and a NI USB-6251 to collect data from LASER based optical measurement system. The sampling rate is of the order 25-100kHz and the measurements are 1-5 minutes.
    The attachment is picture of the LabVIEW program I am using.
    Greatful for some advice......
    Attachments:
    LVprogram.JPG ‏73 KB

    Your file path is only one & the same variable that always throws the same file path to the Write to Measurement File VI; so, it does its job correctly. What you ve to do is, if you want different files, you need to supply different names for them either manually or programmatically.
    You can achieve htis easily, if you think a little bit more...
    - Partha
    LabVIEW - Wires that catch bugs!

  • Loading data from multiple files to multiple tables

    How should I approach on creating SSIS package to load data from multiple files to multiple tables. Also, Files will have data which might overlap so I might have to create stored procedure for it. Ex. 1st day file -data from au.1 - aug 10 and 2nd day
    file might have data from aug.5 to aug 15.  So I might have to look for max and min date and truncate table with in that date range.

    thats ok. ForEachLoop would be able to iterate through the files. You can declare a variable inside loop to capture the filenames. Choose fully qualified as the option in loop
    Then inside loop
    1. Add execute sql task to delete overlapping data from the table. One question here is where will you get date from? Does it come inside filename?
    2. Add a data flow task with file source pointing to file .For this add a suitable connection manager (Excel/Flat file etc) and map the connection string property to filename variable using expressions
    3. Add a OLEDB Destination to point to table. You can use table or view from variable - fast load option and map to variable to make tablename dynamic and just set corresponding value for the variable to get correct tablename
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Joining data in multiple files into a single file using BPM

    Hello All,
             Can someone kindly give me any documentation or step by step procedure to join data in multiple file and display it all in one single file, using BPM.
    Thanks in advance,
    XI_Novice

    hi,
    Check this blog also...
    /people/pooja.pandey/blog/2005/07/27/idocs-multiple-types-collection-in-bpm
    /people/narendra.jain/blog/2005/12/30/various-multi-mappings-and-optimizing-their-implementation-in-integration-processes-bpm-in-xi
    regards

  • Problem while writing data on xls file using jxl API

    Hi,
    I am getting problem while writing data on excel file using jxl api.
    When i write data on file and all handles associated to the file are closed, file size increases but when i open the file nothing is written in it and when file is closed manually from excel window, file size decreased to its original that was before writing data.
    here is code:
              FileOutputStream os = new FileOutputStream(this.dirPath + this.fileName, true);
              WritableWorkbook this.workbook = Workbook.createWorkbook(os);
    after writing data following handler are closed:
    this.os.flush();
                        this.workbook.write();
                        this.workbook.close();
                        this.os.close();
                        this.os = null;
    can any body help me.
    Thanks in advance

    Err, I did help you. I did understand your problem; and I solved it for you. What was missing was that you apparently made no effort to understand what you were being told. Or even consider it. You just argued about it, as though you were the one with the solution, instead of the one whose code didn't work.
    And the other thing that was missing was the part where you said 'thank you' to me for solving your problem. Somewhat more appropriate than biting the hand that fed you, frankly. I do this for nothing, on my own gas, and it's extremely irritating when people keep asking about problems I have already solved for them. I am entitled to discourage that. It's part of making them more efficient actually.
    But it happens often enough that it also makes me think I'm just wasting my time. Probably I am.

  • Writing data to a file in Server

    Hi all,
    In my application i would be writing data to a file which is located in the Server.
    when i tried writing data to a file in my local machine using a Java Application it worked fine .
    Now through the webdynpro application and providing the files path (in server ) ,i am getting file not found exception .
    I am using basic File and i/o operations .
    File abc = new File ("
    servernamer
    folder1
    subfolder1
    filename.dat");
    when i try accessing this path from the command prompt its opening fine.
    Could you please through some light on this .
    thanks,
    swetha .

    >
    KalluriVijay wrote:
    > Hi Swetha,
    > Do one think.
    > InputStream text = null;
    >                int temp = 0;
    >                //File file = new File(wdContext.currentContextElement().getResource().getResourceName().toString());
    >                //wdComponentAPI.getMessageManager().reportSuccess("filePath Vijay:::"+file);     
    > //wdComponentAPI.getMessageManager().reportSuccess("filePath Vijay:::");
    >                     try
    >                     {
    >                     String fileName = wdContext.currentContextElement().getResource().getResourceName().toString();               
    >                     if(fileName.equalsIgnoreCase("ASNCRT.dat"))
    >                     {     
    >                     File file = new File(fileName);                         
    >                     FileOutputStream op = new FileOutputStream(file);          
    >                     if (wdContext.currentContextElement().getResource()!= null)
    >                     {
    >                     text = wdContext.currentContextElement().getResource().read(false);
    >                     while((temp=text.read())!= -1)
    >                     {
    >                     op.write(temp);
    >                     }
    >                     }
    >                     op.flush();
    >                     op.close();
    >                     path = file.getAbsolutePath();
    >                     //wdComponentAPI.getMessageManager().reportSuccess(path);
    >                     }
    >                     else
    >                     {
    >                     wdComponentAPI.getMessageManager().raiseException("Please Check the Filename:Filename should be ASNCRT.dat ",true);     
    >                     }
    >                     }
    >                     catch(Exception ex)               
    >                     {
    >                     ex.printStackTrace();
    >                     }
    > By using this code u can put u r file in to Server Path, then u will get the that .dat file from server path and run the command prompt its opening fine
    > How to get the file from the Server Path:
    > Workbook wb = Workbook.getWorkbook(new File(path));     // For get the file from the Server path
    >
    >   Hope this is help full for u
    > Regards
    > Vijay Kalluri
    This won't work. First, like i said, File class is not for accessing remote files, it is only for local files.
    Second, Workbook class is a class from Java Excel API. He is not working with xls. Anyway that wouldn't work either.

  • Last run date & time & multiple files handling

    Hi frnds,
    i am working on an outbound interface in which i am retrieving data from custom db table,processing it with other db tables and writing  the final output into a file into the application server and updating the custom db table.
    Now i have an issue here when i am giving plant as input in selection screen (select-options), i should also get those plants from my custom table which have no last run date and time.
    How to get that?
    Next part of my question is for multiple plants entry,multiple files have to created in application server.
    Presently, i have concatenated the file path n name.Do i need to loop the same with s_werks.Will it work
    Also i used an internal table for update data storage.When multiple plants are their how to handle the updation.
    Rgds,
    Simran

    Hi.
    In ur reply i did'nt understood two things
    1) this is how i'm doin the selection
        select lt_run_dt
               lt_run_tm
        into table itab1
        from z_table
        where prog_name EQ sy-repid
        AND   plant IN s_werks
    will it give me plants whose last_run_date and last_run_time are not in the z table?
    2)  If you are going with select-option from parameter, then if you have to write a FILE per PLANT. Then you can loop at plant->extract the data-> write to app server-update z table->end loop
    Does that means:
    loop at s_werks
    open dataset
    transfer
    modify
    endloop
    Kindly clarify to solve this issue.
    Rgds,
    Simran

  • Error While Posting Data Of Multiple File to R/3

    Hello,
    I am currently testing with a scenario <b>where a number of XML files are read by XI and their data is passed to R/3 via an RFC call. Each XML File contains one line item data.</b> I am using BPM to achieve this. The problem is: <b>If I test with a single line item data (single file), the scenario works fine and data is updated at the R/3 end. But if I try to put multiple files simultaneously, only one file's data is going into R/3</b>. What can be the problem? Is it something to do with serialization? I have tried using EOIO; but still the same problem persists. I see in SXMB_MONI that all the messages have chequered flag. I have tried debugging the RFC, but it does not work out for multiple calls. Anybody has any idea how this can be solved?
    Regards,
    Amitabha

    Hello Bhavesh,
    Thanks for your reply. My BPM scenario is as follows:
    <b>Receive->Synchronous Send->Asynchronous Send</b>
    In sender channel for XML files, I have used <b>Filename*</b> as the source file name as my files are coming with <b><filename ><timestamp></b> naming convention. Poll interval is <b>5 seconds</b>, Processing mode is <b>by name</b>.
    AT the RFC receiver  channel end, the credentials are all ok and the <b>number of maximum connections is set to 25</b>. I have always tested with no. of messages<5.
    Hope you find this info useful. Awaiting reply.
    Thanks and Warm Regards,
    Amitabha

  • Writing XMP to multiple file formats (PDF, JPEG,  TIFF, etc)

    Hi,
    I am developing a server-side component that embeds XMP data into a file (of various formats) and then provides these files for client download.
    I have been using the XMP toolkit for generating the metadata, however i now have the problem of getting this metadata into the relevant file. I could always develop this myself but it seems like a huge amount of work. So to make my life easier, does anyone know of any toolkits (from adobe or otherwise) that support writing XMP data into different file formats (PDF, JPEG, TIFF, AIFF, MPEG etc) ??
    I am developing in Java so I would prefer Java libraries, however I can always use JNI calls to C/C++ (as i have with the XMP toolkit).
    Any help would be very appreciated.
    Regards,
    Jude

    Greetings,
    I think we should standardize some information, I know for a fack, that I will support adding XMP metadata in the HDF, RIFF, IFF and OLE file formats. If you have any specific suggestions on the chunk information or signature information that I should use, let me know?
    For my part, I was thinking of adding RIFF,IFF chunks with the name \ xmp in those file formats. For OLE, maybe an added stream with the xmp name (in UTF-16).
    Comments welcome everyone!

  • Regarding ssis - Divide data over multiple files

    Hi,
    I have input data like this
    filename       id
    a                   1
    a                  2
    b                 3
    c                3
    i want to send the data different excel sheets
    all 'a' should go one excel file
    b should go one excel file
    if other time z is there  z should go one file    these should happen dynamically
    please help me

    See similar logic explained here
    It even creates the excel sheets on the fly
    http://visakhm.blogspot.in/2013/09/exporting-sqlserver-data-to-multiple.html
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Writing Data to a file using TEXT_IO in Forms

    I have a situtation where i have 5 columns and having arabic as well as english data. when i want to write this data to a txt file using TEXT_IO in a specific format, it writes to a file but as soon as it finds an arabic field, it changes the posistion. how can i write to a txt file in the posistion i want???

    vaishnavinatarajan wrote:
    How to write data to a file without leaving any blank lines in the file? How to check if the cursor is placed in the corner of a notepad file using LAB VIEW?
    If you write data to a file, simply don't include any blank lines. We cannot give more specific advice unless you are telling us how you are writing. Are you writing to a new file or appending to an existing file. If the blank lines already exist, you need to read the entire file, remove the undesired lines from the string, and write the data back.
    Notepad files don't have any "corners". Please describe what you are trying to do.
    What is "LAB VIEW"?
    LabVIEW Champion . Do more with less code and in less time .

  • Problem in writing data to flat file

    Hi,
    I have created an interface with table as source and file as target. My interface is running from long time but its not writing data into file. Any clue?
    -Chikk

    Hi,
    Please, take a look if the target file is locked.
    Try to delete it and put the "Truncate" option from IKM to yes.
    Cezar

  • By a sub VI, Writing data countinously to file by a ''Write' button in Main VI??

    Good morning...day  to all !
    I've made a program, where I'm reading data generated by a device connected to a com port. These data are red from the port to an indicator buffer and then, into a file when a button, " write file" are pressed. I've placed the 'WriteDataToFile.VI' in a Sub VI placed in Main VI.
    When my Main Program starts and I switch a start button, a file dialog box opens, so I can choose an existing file or a new file to write data to!
    I want to Make a Button named  " Write file" so when pressed , the Dialog box opens and I can choose a file to write to.
    In that way I can avoid the Self pop up dialog box.
    I've spended the hole weekend  trying doing that, but no succes. The biggist problem by that is:
     To write a continously to a file I  also need to continously read the data from the port, And because of that, I got to write the data to a file as quickly as possible when Red from the port. So I gotta put the WriteDataToFile.VI 'sub', in the ReadData:vi 'Sub'. By that I always get the Dialog box poped up, by each while loop iteration. Just because the Software to the open Dialog Box (Write file), is placed in the ReadDataVI, Sub.
    Please Help me with that Guys , girls, any one, also peoble from Mars To!
    Attachements !!
    Regards
    H.F.Zamzam    
    HFZ
    Attachments:
    ReadDataWriteToFile.vi ‏62 KB

    Hi Zamzam,
    I think the point you should work on is the architecture of your whole application, LabVIEW has very well designed templates.
    If you go to new >> new... >> vi from template >> frameworks >> design pattern >> user interface event handler
    It is a very robust architecture with which you can draw cases for (almost) any kind of event such as a click on a button.
    in your application, you could choose the file to write on the first run, then put the file refnum in a shift register and add an event case handled by the "write to file" button that writes the acquired datas.
    You could even go further and set that "wite fo file" case on other event, for instance new data from the port com.
    wooopps... I tried to be as clear as I could but english is not my natural language , so please tell me you need some more help
    When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!"

  • How to read data from multiple files and append in columns in one file

    Hi Guys,
    I have a problem in appending data from files in different columns. I have attachement has file A and B which I am reading and not able to get data as in file Result.txt. Please comment on how can I do this
    Solved!
    Go to Solution.
    Attachments:
    Write to file.vi ‏13 KB
    A.txt.txt ‏1 KB
    B.txt.txt ‏1 KB

    You cannot append columns to an existing file. Since the data is arrange line-by-line as one long linear string in the file, you can only append rows. A new row needs to be interlaced into the original file, shifting everything else. If you want to append rows, you need to build the entire output structure in memory and then write all at once.
    (I also don't think you need to set the file positions, it will be remembered from the last write operation.)
    Unless the files are gigantic, here's what I would do:
    (Also note that some of your rows have an extra tab at the end. If this is normal, you need a little bit more code to strop out empty columns. I include cleaned up files in the attachment. I also would not call them A.txt.txt etc. A plain A.txt is probably sufficient.)
    EDIT: It seems Dennis's solution is similar )
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Write to fileMOD.zip ‏6 KB
    MergeColumns.png ‏6 KB

  • Writing data in text file..

    1. check the file name in D:\\temp\\test.txt
    2. if it exists, then open file. if there is data, then read data. after the last record, it writes new data.
    3. if it does not exist, create text.txt file and write data into text.txt file.
    so far, I have a code..
    import java.io.*;
    import java.util.*;
    public class Main {
    public static void main(String[] args) {
    String filename="test";
    String format = "%1$-9s%2$-3s%3$-30s%4$-30s%5$-30s\n";
    String arraydata[] = { "John", "F.", "Kennedy", " ", "t", "John2", "F2.", "Kennedy2", " ", "t2"};
    String cnt_id ="2";
    int cnt_orderid = Integer.valueOf(cnt_id);
    try
    PrintStream ps = new PrintStream(new FileOutputStream("D:\\temp\\"+filename+".txt"));
    for (int i=1; i<cnt_orderid; i++)
    ps.println(String.format(format, (Object[])arraydata)); // write in test.txt file
    ps.close();
    catch (Exception e)
    System.out.println(e);
    my question is..
    1. how to check the file exists or not
    2. how to write the data in the new line after the last data in the file.

    1. Use a File object.
    File file = new File("someFile.txt");
    if (file.exists()) { ... }2. Consider using FileWriter; the constructor allows you to append to the end of the file:
    FileWriter fileWriter = new FileWriter(file, true);Michael

Maybe you are looking for

  • Long list of "software" problems on iphone 4.

    My wife and I have iphone 4s, purchased about a year apart (I got mine as a cheaper leftover after the 4S came out.) My phone is fine but hers is having a long list of weird problems nothing seems to permanently fix. It is about 2 1/2 years old, and

  • NW2004S BI with Java?

    We are upgrading our BW system running on Nw2004 to NW2004S. The documentation says we need to install a JAva instance after the upgrade of the ABAP instance.Does BI running on Nw2004S need a Java instance?

  • Cash Sale - Invoice

    Hi Gurus, Can i do cash invoice with reference to sale order(BV) without complete my PGI. I tried but it is asking for PGI and then allowing to do billing. Any clue Thanks, MM

  • Hold Me! Squeeze Me! STRETCH ME!?!

    Greetings! I recently downloaded two free plug-ins from Too Much Too Soon http://www.mattias.nu/plugins/ called Anamorphic Squeeze and Smart Anamorphic which presumably convert 4:3 into 16:9. When I apply either of them this is what seems to happen.

  • How to export iphoto 'movie' to final cut pro

    I am a novice to iPhoto, but use Final Cut for movies. Is there a way to create a slideshow in iPhoto and then export that into a file suitable for importing into FCP?