Print data to the beginning of a file

Hi,
I have written this code to wite data to a textfile:
PrintWriter FeedStream = new PrintWriter(new FileOutputStream(feed_path, true));
FeedStream.println(text);
FeedStream.close();The code works fine but it writes the data at the end of the file whereas I want it at the beginning of the file. How to solve this?
Thanks in advance,
leonard

Well, the reason is that I want to print the data in another application and saving the data this way is more convenient.
E.g.
application 1 prints this to a file:
L1 Test=45
L2 Temp=10
then the same application maybe has to write more data to the file at another time, and adding:
L1 Test=39
L2 Temp=12
However application 2 that monitors the file every 6h should analyse the data from the newst to the oldest. For the conveniance when parsing the file with application 2 I want to add the data to the beginning of the file.

Similar Messages

  • Appending data to the beginning of a file

    How do you write data to the first line of a file without overwriting the data which is already present?
    Data before:
    888826759 100011021
    888826767 100011026
    888826916 100011024
    888826916 100011023
    888826940 100011029
    888826940 100011028
    888857389 100011020
    888871480 100011029
    What I want data to look like after:
    ABC
    888826759 100011021
    888826767 100011026
    888826916 100011024
    888826916 100011023
    888826940 100011029
    888826940 100011028
    888857389 100011020
    888871480 100011029
    I'm trying this, but it doesn't work as it overwrites the first piece of data in the file
    file.seek(0);              
    file.writeBytes("ABC");so that the output is:
    ABC826759 100011021
    Edited by: drakester on Oct 12, 2007 10:59 AM

    You might be able to write the file into one of the Collection Lists that maintain order (like LinkedList, but there are others), add the first line, and then rewrite the file from the list. You might also find the Collections methods reverse and rotate could be useful if you add the data at the end of the list.
    You could also create an array and fill the 2nd through last elements with the file lines, insert your data as the first element, then write the file from the array.
    Ther are a number of variations on the above approaches.

  • Appending "something" at the beginning of a file

    Hello,
    I am trying to append a character to the beginning of a file, doesnt seem to work with RandomFileAccess. I first called the seek() methond
    seek(0); //zero to send the file pointer to the front 
    write((byte) myCharValue);apparently it overwrites the value at the front instead of adding for example:
    before running the code the file has: "Java is Cool!"
    after running the code the file has: "xava is Cool!"
    Any Ideas?
    Thanks

    1. Create a new file.
    2. Write out whatever you wanted to insert at the beginning.
    3. Copy the data from the old file and append it to the new file.
    4. Close the files.
    5. Delete the old file.
    6. Rename the new file.

  • How to delete the beginning of a file?

    Hi,
    is there a way to delete the beginning of a file, or do I have to copy the rest of the file and create a new one and then delete the old one?
    Lets say my file contains "ThisIsMyFile" and I want to delete "This", so that my new file contains "IsMyFile", how can I do this?
    thanx

    You have to copy.

  • How can i retrieved data into the infocube from archived files

    hi,
    i have archived cube data and i have to load data into the cube from archived files.
    so now i want to find archived files and how to load data into the cube.
    thanks

    Hi.....
    Reloading archived data should be an exception rather than the general case, since data should be
    archived only if it is not needed in the database anymore. When the archived data target is serving also as a
    datamart to populate other data targets, Its recommend that you load the data to a copy of the original
    (archived) data target, and combine the two resulting data targets with a MultiProvider.
    In order to reload the data to a data target, you have to use the export DataSource of the archived data
    target. Therefore, you create an update rule based on the respective InfoSource (technical name 8<data
    target name>). You then trigger the upload either by using ‘Update ODS data in data target’ or by
    replicating the DataSources of the MYSELF source system and subsequently scheduling an InfoPackage
    for the respective InfoSource
    If you want to read the data for reporting or
    control purposes, you have to write a report, which reads data from the archive files sequentially.
    Alternatively, you can also use the Archiving Information System (AS). This tool enables you to define an
    InfoStructure, and create reports based on these InfoStructures. The InfoStructures define an index for
    the archive file data. At the moment, the archiving process in the BW system does not fill the
    InfoStructures during the archiving session automatically. This has to be performed manually when
    needed.
    Another way of displaying data from the archive file is by using the ‘Extractor checker’ (TCODE RSA3).
    Enter the name of the export DataSource of the respective data target (name of the data target preceded
    by ‘8’), and choose the archive files that are to be read. The extractor checker reads the selected archive
    files sequentially. Selection conditions can be entered for filtering but have to be entered in in internal
    format
    It will remain same in the change log table.
    Check this link :
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b32837f2-0c01-0010-68a3-c45f8443f01d
    Hope this helps you...........
    Regards,
    Debjani............

  • How would I erase the beginning of a file?

    I want to be able to erase the beginning of a file, while writing to the end...WITHOUT reading the whole file and writing it again because that would be a waste of resourses. Obviously I know that option is available.
    My situation is that I am adding lines to a log file, and I want to remove any entries that are X hours old. Logging a lot of information would mean that every few seconds, an entry is older than X hours and needs to be removed. It doesnt have a set number of lines so I can't just recycle the file by doing something like: if at line number Y, start at line 1 and remember the current line number.
    Adding to the top of the file, pushing the others lines down, and making cuts at the end would also work, but the same situation arises, how do I add to the beginning of the file, without having to copy the entire file to add the entry to the top.
    The reason I don't want to read the whole file is because having to read the whole file and write the whole file when an entry is made is time consuming and wastes CPU and memory, especially when the logs are coming in several lines a second.

    I would think it could easily be done. say you want to erase the first 10 bytes, why cant you just say move the start of the file up 10 bytes. Somewhere in the filesystem the start of the file is stored. I found underlying file copying that claims this in FileChannel's transferTo and transferFrom:
    This method is potentially much more efficient than a simple loop that reads from this channel and writes to the target channel. Many operating systems can transfer bytes directly from the filesystem cache to the target channel without actually copying them.
    If I can't just chop, I'll have to copy quickly at scheduled intervals.
    This is code I ran to test the above quote:
        public static void main(String[] args) throws Exception{
            args = new String[2];
            BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("Enter File Name:");
            args[0] = input.readLine();
            System.out.println("Enter test (0-2):");
            args[1] = input.readLine();
            long time = System.currentTimeMillis();
            int version = Integer.parseInt(args[1]);
            switch (version) {
                case 0:
                    BufferedReader in = new BufferedReader(new FileReader(args[0]));
                    PrintWriter out = new PrintWriter(new FileWriter("tempfile.txt"));
                    in.readLine();//skip line.
                    for (String line = in.readLine();line != null;line = in.readLine()) {
                        out.println(line);
                    in.close();
                    out.close();
                    break;
                case 1:
                    RandomAccessFile raf = new RandomAccessFile(args[0],"rw");
                    String line = raf.readLine();
                    long offset = raf.getFilePointer();
                    byte[] b = new byte[1024];
                    int bytes = 1024;
                    long index = 0;
                    System.out.println("index = " + raf.getFilePointer());
                    System.out.println("index = " + line.length());
                    while(bytes == 1024) {
                        bytes = raf.read(b);
                        index = raf.getFilePointer();
                        raf.seek(index - bytes - offset);
                        raf.write(b,0,bytes);
                        raf.seek(index);
                    raf.setLength(raf.length()-offset);
                    raf.close();
                    break;
                case 2:
                    RandomAccessFile raf2 = new RandomAccessFile(args[0],"rw");
                    String line2 = raf2.readLine();
                    long offset2 = raf2.getFilePointer();
                    FileChannel f = raf2.getChannel();
                    FileChannel g = f.position(0);
                    g.transferTo(offset2,raf2.length() - offset2,f);
                    raf2.setLength(raf2.length()-offset2);
                    raf2.close();
                    break;
            System.out.println(System.currentTimeMillis() - time);
        }and had these results
    166MB Log File
    Linux Mandrake 900Mhz
    Case 0 = 32914 ms
    Case 1 (1k byte[]) = 15043 ms
    Case 1 (16k byte[]) = 6988 ms
    Case 1 (1MB byte[] = 6113 ms
    Case 2 = 6188 ms
    :-/ guess this proves that the FileChannel can't chop

  • Append a line at the beginning of a file via UTL_FILE

    Hello,
    is there a way to append a line to the beginning of a file instead of at the end of an existing file via UTL_FILE?
    Thanks in advance,
    Geert

    No, you would have to create a new file.

  • Saving the data into the tab limited text file

    Dear Friends ,
    please help me at the earliest possible , i want to store the data into an text file which is tab limited ,previously i was able to the same into the excel sheet using the jakarta HSSF POI , an open source library to store the data into the EXCEL sheet , now friends please tell me whether is there any other open source to store the data into the tab limited text file what i mean by tablimited is the data is to be saved as
    Name        Email-id        phone          streeet          city
    sri            @some.com     9434           jahdui          hye
    asdf         @.com           3455           sdgsdf         retlike this so please suggest me
    thank you in advance,
    bye
    sriharsha

    Consult the docs for BufferedWriter and from there.
    regards
    Christian
    import java.io.*;
    public class Test
         public static void main(String[] args)
              BufferedWriter writer;
              String[][] s = { {"Name","Email-id","phone","streeet","city"},
                        {"sri","@some.com","9434","jahdui","hye"},
                        {"asdf","@.com","3455","sdgsdf","ret"}};
              try {
                   writer = new BufferedWriter(new FileWriter("out.txt"));
                   for (int j=0; j< s.length; j++) {
                        for (int i = 0; i < s[j].length; ++i) {
                             writer.write(s[j]+"\t");
                        writer.newLine();
                   writer.close();
              } catch (IOException e) {
                   e.printStackTrace();

  • Printing date in the actual picture?

    Hi, I have iPhoto on two machines. One older and one newer. However, I cannot figure out how to save an image with the date -in- the image. My wife wants to print photos that included the date taken on the picture. Is there a way I can do this in iPhoto?
    Our old camera automatically printed the date in the image, but the new one seemingly does not. The file has the information on the date and time taken, but we cannot figure out how to get that information onto the image itself.
    Help?
    Thanks,
    -Josh2

    Josh2, hi, do you have AppleWorks?
    I just tried it, if you don't have too many photos to add dates to...
    Open AppleWorks, click on the Drawing Starting Point. Go up to File>Insert, locate the photo you wish to date, Then click on the top left button on the tool bar, it looks like A on a graph paper background. Figure out how to choose your font color, adjust your text frame to the proper size, type the date and any comments. Click Save up in the File Menu. I made some cutesy prints. "Don't we clean up Good?" That sort of thing.
    My Kodak digital has the date on photo option , it has just saved me money. Get out your instructions. If it can do it, it will tell you how to set it.

  • Xtra character appearing at the begining of a file written by my java pgm

    Hi,
    I am trying to write an object to an output file (which is a HTML document). But when the object is written at the
    begining of the file the following character appears
    ' �� '
    Is there a way to supress this character when the file is written ?
    My java program is running in a Sun Solaris machine and the file is created in the same directory.
    Thanks
    Bala.

    You have to give a lot more info... Are you trying to
    write the object as an object (ie serialize it) or are you
    simply trying to write the contents (data held in) this
    object to an HTML file? Some code would help too.....
    If you are simply wanting the contents written
    be sure you are not trying to use an ObjectOutputStream...
    If you are trying to write the Object (ie serialize it) then
    you have to remember that there are chances of
    non-printable characters being written...

  • Data from the outputstream to a file in the server.

    Hello everyone,
    I have put the data in the outputstream. I need to place the data in a pdf and put it in a location in the unix box. Any suggestion? Below is the code i have written so far.
    public ByteArrayInputStream inputStream;
    public ByteArrayOutputStream pdfFile;
    public ServletOutputStream os;
    DataObject sessionDictionary = (DataObject)pageContext.getNamedDataObject("_SessionParameters");
    HttpServletResponse response = (HttpServletResponse)sessionDictionary.selectValue(null,"HttpServletResponse");
    try {
    os = response.getOutputStream();
    String contentDisposition = "attachment;filename=PrintPage.pdf";
    response.setHeader("Content-Disposition",contentDisposition);
    response.setContentType("application/pdf");
    XMLNode xmlNode = (XMLNode) am.invokeMethod("getEmpDataXML"); //This method invokes the required data from the view object
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    xmlNode.print(outputStream);
    inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    pdfFile = new ByteArrayOutputStream();
    }catch(Exception e)
    throw new OAException("Hello "+e.getMessage(), OAException.ERROR);
    Thank You in advance.
    Pk

    hi Swetha,
    Go through the below links and these will solve your problem
    [How to Upload and Download Files in a Web Dynpro for Java Application|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/9076a593-2b08-2d10-2890-9a7078246ec4?QuickLink=index&overridelayout=true]
    [Storing data in a Text File in server  |Re: Storing data in a Text File.;
    Hope these links are useful
    regards
    Mahesh

  • Printing date in the cheque date box column

    Hello all,
    I want to print the date in the cheque box column automatically.I used sy-datum.but its not coming in the proper field of day,month and year.can anyone please help me to do it .
    Thank in advance.

    Check user master records for date format. Which tool did you use SapScript or Smartforms, you could alsop look for date formatting in those tools.
    Smartforms : Smart Forms, Using SAP Smart Forms, Using Parameters in a Form, Using Fields in the Form, Output Options for Field Contents
    Sapscript : BC Style and Form Maintenance, Formatting Options, Date Mask
    NB: Better use sy-datlo if your systems have users worldwide.
    Regards,
    Raymond

  • How to add data in the saved spreadshee​t file

    Hi all,
    I am having trouble in adding data onto an already saved spreadsheet file. I don't want to overwrite the old file but modify it, such that the new data is stored below the old data. Or
    As I am saving the data in a 2-D array in the VI, where the first row of the array is occupied only, each time I take new measurements the old data is lost, is there a way to keep the old data and store the new one below the old data in the same array. Any help in this matter would be appreciated.
    Regards
    Ibtasam
    Message Edited by Ibtasam on 07-11-2007 05:58 AM
    In the name of Allah, the most mercifull and the most Gracious

    Hi all,
    I have actually managed to find a way to add comments before saving the data. Following steps are followed:
    1.) Add a table on the front panell
    2.) Connect the table as an indicator to the output array
    3.)Finally make a varaible by right clicking on the table indicator (Block diagram) and connect this variable as an input to the Write to Spreadsheet.vi
    this way you get the array output into the table and you can add comments in the table and then save it. If any body need any more information then please let me know
    regards
    Ibtasam
    In the name of Allah, the most mercifull and the most Gracious

  • Problem printing date on the form

    Hello friends ,
    I am doing form for the HR . Is there any special formatting needed to print the date on the form . I am doing this .
    &t_payment-paydate& in the main window of the form .
    t_payment is the table and paydate the date of payment . But instead of printing 1/22/2006 . It is printing 3//20/07/2 some junk value . Is it the format related problem ?
    Any suggestions . You help would be greatly appreciated .
    Regards & Thanks ,
    Hari

    HI,
    You can do like this.
    You make the following changes in the program
    1. Define a character type field
         data: v_payment_date(10) type c.
    2.  Assign the date value to the character field
          write t_payment-paydate to v_payment_date.
    You make the following changes in your sapscript text element.
        instead of using field t_payment-paydate use v_payment_date.
    Thanks
    Ramakrishna

  • How to test or view data if the source is XML files..?

    Hi,
    I just got a doubt..
    How can we test or view data from BI Admintool if the source is XML files.
    If it is database we can perform "Update Row Count" or "view data" from physical layer.
    I am just going through the "sample sales" example and could not find the option to test
    connectivity with xml file..(I can see the directory which points to samplesales and xml files..
    but how can I view those data in BI admintool)..
    Help would be appreciable..
    Thanks and Regards,
    Sri.

    Hi Sri,
    Yes, this option is not available for XML and multidimensional sources. Check "Show row count in physical view" in Table 2-1 documented here ,
    http://docs.oracle.com/cd/E21764_01/bi.1111/e10540/planning.htm#BABEFIHE
    Rgds,
    Dpka

Maybe you are looking for

  • Deployment to WebLogic 8.1

    I'm a JSC novice working for a big UK company. The target server for my simple Web app is WebLogic 8.1. The application was easy to develop thanks to JSC, however, when I deployed it to WebLogic for the first time I encountered a rat�s nest of proble

  • Error while using ant of webcenter spaces.

    Hi All. I am using jdev 11.1.1.5 . we using webcenter spaces application.While doing clean stage of ant option , i got this error. BUILD FAILED C:\siemens_repositories\workspace_siemens_occ\dev\OCCDesignWebCenterSpaces\WebCenterSpacesExtensionLibrary

  • Can't update ADOBE after many attempts. Why won't it work?

    Keep getting messages saying I must update ADOBE. Keep following directions for update. Then I'm disallowed access to anything that requires ADOBE update and a red typed message appears again saying I need to update ADOBE. Why won't this work ? I am

  • HT201272 It would be helpful to have a button: click here to download

    The little cloud symbol in the dog eared corner of the movie I purchased was easily overlooked and confusing. A suggestion to Apple; It would be so much easier if there were a button that said "download now" or "click here to download", as an option

  • Video Green in Win8 with Hardware Acceleration enabled

    Hi, I need to be able to disable hardware acceleration in flash player in Windows 8. I managed to do this in the past, however after reinstallation this time I have been unsuccessful. Last time, I somehow managed downgrade to a earlier version which