Writing in Files at the Line (END-1)

I need to make my program write something not at the end of the program, but just before the last line. The basic idea is to have the word END at the end of the file, but when writing new things, I can either delete the things written before (which is not an option) or write at the end of the file, but then the new things I write will be below the end.
Or, alternately, if there is a command which can tell the program to read the whole file, from top to bottom, that would be nice too.

The best way to do that would be to retrieve all the text from the file into a String or StringBuffer object, and then append text at the places you want to append to.
You can then take your modified String and rewrite over the existing text in the file.

Similar Messages

  • File Problem (getting line ends with \r\n)

    I used readLine method     to read the line. It returns string.
    I want to get the lined that ends with 0D0A ( \r \n ).
    In the file in between there are many 0D. So my while loop
    returns all the lines ends with 0D. But I need only the lines ending with 0D0A.
    How can I differntiate these two types of lines
    .....0D
    ...........0D0A
    Is there any method in Java to differentiate these two lines.
    reading char by char is time consuming process and it produce some overhead.
    I think reading line by line gives the better solution
    here is the code
    import java.io.*;
    class checkAcc {
    public static void main(String as[]) {
    try {
    BufferedReader bf = new BufferedReader(new InputStreamReader(new FileInputStream("exa.dat")));
    String s = null;
    byte[] b;
    while((s = bf.readLine()) != null) {
    System.out.println("From Dat File ===> " + s);
    } catch(IOException ie) {
    System.out.println(ie);
    Can any one pls give me the idea ...

    That's the nature of readLine() my friend. The definition is as such:
    Read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.
    There isn't anything wrong (performance wise) with using read() and processing it character-by-character.
    tajenkins

  • Access denied error while writing a file to the file system - myfileupload.saveas() throws system.unauthorizedexception

    hi,
    as part of my requirement , i have to perform read and  write  operations of  few files [ using the file upload control in my custom visual web part] and on submit button click.
    but while writing these files - with the help of  fileupload control - and when i use  myfileupload.saveas(mylocation);
    - i am saving these files into my D:\ drive of my server , where i am executing my code -, am getting access denied error.
    it throws system.unauthorizedexception.
    i have given full control on that folder where i was trying to store my attached files. and also  after following asp.net forums,
    i have added  iusr group added and performed all those steps such that, the file is saved in my D:\ drive.
    but unfortunately  that didnt happen.
    also
    a) i am trying the code with runwithelevatedprivileges(delegate() )  code
    b) shared the drive within the  d :drive where i want o save the files.
    c) given the full privieleges for the app pool identity- in my case , its
    network service.
    the  other strange thing is that, the same code works perfectly in  other machine, where the same sp, vs 2012  etc were installed .
    would like to know, any other changes/ steps i need to make it on this  server, where i am getting the  error.
    help is  appreciated!

    vishnuS1984 wrote:
    Hi Friends,
    I have gone through scores of examples and i am failing to understand the right thing to be done to copy a file from one directory to another. Here is my class...So let's see... C:\GetMe1 is a directory on your machine, right? And this is what you are doing with that directory:
    public static void copyFiles(File src, File dest) throws IOException
    // dest is a 'File' object but represents the C:\GetMe1 directory, right?
    fout = new FileOutputStream (dest);If it's a directory, where in your code are you appending the source file name to the path, before trying to open an output stream on it? You're not.
    BTW, this is awful:
    catch (IOException e)
    IOException wrapper = new IOException("copyFiles: Unable to copy file: " +
    src.getAbsolutePath() + "to" + dest.getAbsolutePath()+".");
    wrapper.initCause(e);
    wrapper.setStackTrace(e.getStackTrace());
    throw wrapper;
    }1) You're hiding the original IOException and replacing it with your own? For what good purpose?
    2) Even if you had a good reason to do that, this would be simpler and better:
    throw new IOException("your custom message goes here", e);
    rather than explicitly invokign initCause and setStackTrace. Yuck!

  • To avoid writing database code in the front end

    Hello,
    I am working on a database application using 10g database as backend and dotnet as front end. I wish to execute only oracle stored procedure for all the select (to avoid hard parse and use of bind variable), DDL and DML operations; just to avoid writing database code in the front end. Can anyone please give me a little examples of :
    1.Select query's output to be return as resultset by stored procedure.
    2.DML example by stored procedure.
    3.Any DDL example by stored procedure.
    using scott.emp, so that i would just call the stored procedure, rather than giving select,DML and/or DDL commands in the front end. Even though i have read in the documentation, but a clear cut examples will help me to get into clear concept as well.
    Thanks & Regards
    Girish Sharma

    Hi...
    -->Select example
    create or replace procedure get_emp(rc out sys_refcursor)
    is
    begin
    open rc for select * from emp;
    end;
    -->DML example
    create or replace procedure do_dml_emp(pempid in number,
    pempname varchar2,
    result out number)
    is
    begin
    insert into emp(empid,empname) values(pempid,pempname) returning empid into result;
    exception
    when others then
    result:=-1;
    end;
    -->DDL example
    create or replace procedure ddl_emp(colname varchar2,
    coltype varchar2,
    result out number)
    is
    begin
    result:=-1;
    execute immediate 'alter table emp add column ' || colname || ' ' || coltype ;
    result:=1;
    end;

  • How do you send a File from the Clinent End To the Server?

    Hi, I'm jut learing Java and am tring to send a file from the Cleints end to the Servers' end, I know how to do this in Php, but its some what different in Java, i know where is a File Class which i can post the information into but for some reason it woudn't work
    <%@ page import=" javax.servlet.*, java.io.File" %>
    <%
    String fullname, emailadds, genre, filename;
    fullname = request.getParameter("Name");
    emailadds = request.getParameter("email");
    genre = request.getParameter("genre");
    filename = request.getParameter("clip");
    File file = new File();
    file.isFile();
    if (file.isFile())
    out.print("File is true");
    else
    out.print("file ain't there");
    %>
    just as a tester i tried this to see if file is being read, but it won't compile
    I keep getting this error sign! Have i missed out a lib or somthing?
    \upload_jsp.java:52: cannot find symbol
    symbol : constructor File()
    location: class java.io.File
    File file = new File();

    Sham, dont show your anger... and dont use provocative words...
    Now, coming to your problems.
    your jsp/html should contain some thing like
    <form action="/uploadServlet" method="post">
    <input type="file" name="file"/>
    <input type ="submit" value="upload"/>
    </form>and for servlet code, refer to
    http://forum.java.sun.com/thread.jspa?threadID=516176&messageID=2461686
    or the easiest way would be to use 'commons-fileupload' api available on http://jakarta.apache.org/commons/

  • [svn:fx-4.x] 14731: change the line ending to LF so this script will run properly on Mac and Unix .

    Revision: 14731
    Revision: 14731
    Author:   [email protected]
    Date:     2010-03-12 11:06:04 -0800 (Fri, 12 Mar 2010)
    Log Message:
    change the line ending to LF so this script will run properly on Mac and Unix.  Some testsuites were breaking because this script was not executing properly on mac
    QE notes: fix for testsuites
    Doc notes: no
    Bugs: no
    Reviewer: no
    Tests run: no
    Is noteworthy for integration: no
    Modified Paths:
        flex/sdk/branches/4.x/bin/fontswf

    On reflection, it seems much easier/safer to do something like this instead...
    When running in Arch, but viewing a partition with another installation's data on it, do directory listings like this:
    ls -l | FILTER
    where FILTER is a script that pulls out the Arch-announced users and groups, converts them to numeric if necessary (according to Arch's understanding), and then stuffs back in what the other installation thinks are the symbols corresponding to those numbers. This was easy enough to do, and doesn't risk breaking anything.
    Marking as SOLVED, but I'd still welcome feedback about the different ways different distributions understand the groups I cited. It's very hard to track this info down.

  • Writing a file to the server using an applet...?

    Hi,
    I've been searching the web now for almost a day trying to find some help in how to do this... The biggest problem is that I'm kind of a newbie (not a total beginner, but this is the first time I've ventured into applet creation)
    What I'm trying to do is writing a simple web-page updater... i.e. This is what it should be able to do:
    1) Read HTML page and parse it so that I can change the important parts (the info on the page, not the actual HTML code) - DONE
    2) Present the information and let the user change it as (s)he sees fit - DONE
    3) generate the new HTML and write it back as a file on the server (replacing the old one) -- PROBLEM -- :)
    I think (!?) that I should be able to do this using the HttpURLConnection() POST method in addition to a PHP script on the server moving the file around once it's been uploaded. I don't, however, have a clue as to what the code should look like to accomplish something like this...(as I've never used it before, and can't seem to find sample code that would be even close to what I'm trying to do)
    How can this be done? Also, is there a simpler way of doing this?
    Thanks for taking the time to read that :)
    -NRGizeR

    as I said, I will gladly take suggestions :)
    again, I'm new to all of this and I don't really know what things in java (or any of the script languages for that matter) can or cannot do...
    Even if there is a better way, I would still know if this is solvable tho (I just want to get my head straight after banging it against this wall for the past few days) :), but as I said, any suggestions would be appreciated...

  • PDF file transfer writing target file with the same source file name

    Hi to all,
    I want to transfer a PDF file from a SOURCE folder to a TARGET folder. My problem is that I want the target pdf file has the same name of the source pdf file. How can I do this? I have to look for some parameters in the sender or receiver channels?
    Thanks to all.

    Hi Gabriele,
    If you want to FTP the pdf file from source to target directory, use this blog.  It doesn't require any IR devlopment.
    /people/william.li/blog/2006/09/08/how-to-send-any-data-even-binary-through-xi-without-using-the-integration-repository
    Also, In sender and receiver comm channels select "Set/Use Adapter specific message attributes" and "File Name" to get the same file name in the target directory.
    Regards,
    Sreenivas

  • Problems downloading a program/file off the internet, end up as Excel files

    When I attempt to download a program or a file off the internet, and save it to disk it appears as an unreadable excel spreadsheet on my desktop. What is going on?

    Hi, Mary.
    1. Can you provide an example, such as a URL / link to a file you have attempted to download?
    2. See my "Resetting Launch Services" FAQ.
    Good luck!
    Dr. Smoke
    Author: Troubleshooting Mac® OS X
    Note: The information provided in the link(s) above is freely available. However, because I own The X Lab™, a commercial Web site to which some of these links point, the Apple Discussions Terms of Use require I include the following disclosure statement with this post:
    I may receive some form of compensation, financial or otherwise, from my recommendation or link.

  • Writing a file with the OutputStream

    I'm trying to upload a file using Java's included ftp functionality.
    currently I'm trying to figure out how to upload a file. The connection and works.
    The code I found for the ftp connection indicated that I should use the following code to upload..
    URLConnection urlc = url.openConnection();
    OutputStream os = urlc.getOutputStream();
    I've read the documentation for the outputstream and looked for help tutorials on the web etc, but still haven't been able to figure out what I'm doing.
    I need the output stream to write a file to the ftp server. I can get it to put a file there, but so far its just been an empty file. How do I get it to actually write the file with its contents etc.
    thanks for the help

    never mind :) I think I figured it out.
    I just created a File object for the file, then opened a fileinputstream to read the file in and wrote that output using the output stream.
    it seems to work.

  • PLEASE HELP! Writing a file on the OAS

    Hi,
    I have a question please, I'm been able to create a file on the OAS which is my local machine on directory "c:\temp" with no problem :). but if I run the form from another workstation, it gives me an error "WUT-118 Application Server doesnt or is of zero file".
    what I see is, it looks to locate this directory on the worksation not "OAS".
    Any ideas?
    I have setup the webutil:
    transfer.appsrv.enabled=TRUE
    transfer.appsrv.workAreaRoot=c:\temp
    transfer.appsrv.accessControl=TRUE
    transfer.appsrv.write.1=c:\temp
    transfer.appsrv.read.1=c:\temp
    Am I missing anything here? Do I need to add anything to formsweb.cfg?

    Hi,
    I have a question please, I'm been able to create a file on the OAS which is my local machine on directory "c:\temp" with no problem :). but if I run the form from another workstation, it gives me an error "WUT-118 Application Server doesnt or is of zero file".
    what I see is, it looks to locate this directory on the worksation not "OAS".
    Any ideas?
    I have setup the webutil:
    transfer.appsrv.enabled=TRUE
    transfer.appsrv.workAreaRoot=c:\temp
    transfer.appsrv.accessControl=TRUE
    transfer.appsrv.write.1=c:\temp
    transfer.appsrv.read.1=c:\temp
    Am I missing anything here? Do I need to add anything to formsweb.cfg?

  • Unable to Receive Files at the Receiver end

    Hello All,
    I have configured scenario Proxy to File with 1:2 transformation (Interface collections) ie
    1 Sender and  Receiver Service
    1 Sender interface
    2 Receiver interface
    1 Message and interface mapping
    1 Receiver determination
    1 Interface determination
    2 Receiver file channel with FCC
    The QoS is Exactly Once.
    My scenario is failing at Adapter Engine (Receiver end) failing to create 2 text files.
    My Question is
    1. The Status of the File Receiver channel in monitoring are in error status displaying "Message processing failed. Cause: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error: invalid receiver channel 'a3478068e95133a8ad28777a3fe1344d'" What is the reason for this ? I checked the Cache update and cache is upto date.
    2.In SXMB_MONI , When Checked the trace part of Receiver Determination it correctly displays
    "<Trace level="2" type="T">Number of Receivers:1</Trace> "
    But when i checked Trace for Interface Determination it is displaying " InterfaceCollection</Trace>
      <Trace level="2" type="T">...valid InbIf without Condition: InterfaceCollection</Trace>
      <Trace level="2" type="T">Number of receiving Interfaces:1</Trace> "
    Here it should display "Number of receiving Interfaces:2 " Right?   What is the reason for this ? do we have todo multimapping?
    3.In Message monitoring for Adapter Engine i could see messages in Holding state. what is the specific reason in his case (I know the literal/functional meaning) of messages going to holding state  . "Maintain Order at Runtime" is checked in Interface Determination?
    May I know in which situation the messages would goto into holding state (isit because IE was not able to find 2 receiver interface)  and without unchecking the "Maintain Order at Runtime" option and manual intervention isit possible to process the scenario successfully?
    Many thanks in Advance .
    Regards,
    Pavithra

    Hello Ninad,
    Since I am using EHP 1 SAP NetWeaver PI 7.11 , there is no explicit option of selecting "Enhanced Interface Determination" ( Its understood implicitly through the Signature tab in Message mapping (1:n transformation)) and I have done multimapping as message mapping (In the mapping editor, switch to the Signature tab page) for my scenario
    The cache (AE) is perfectly fine
    I am noting down my observation here.
    My scenario uses QoS EO and the " Maintain Order at Runtime" option was checked. There were many System error messages due to other issues for the previous month and holding messages for this month.
    I guess due to this the channels were in  error though the channels' status were in green but it was displaying message " Message processing failed. Cause:com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error: invalid receiver channel '1ac04de4d1103d09b5b9c764c8895e98'"
    Now I filtered all the 'system error' messages with Sequence Id and deleted all of them and Resent all the holding messages and there were no message in holding .Now again i tried sending some data's ...the channel are functioning fine and no such error messages are displayed
    Regards,
    Pavithra

  • JSP Writing to file on the client machine

    Hi Java Gurus,
    I would like to know if it's possible to store (save) information to a file on a client machine from a JSP Application?
    Or let me know good tips to save some data on the client machine... Thanks a lot!
    Nalee

    Hi Gallegux,
    Sorry, I don't mean to sound dense. Here is my JSP page. Do you mean physically on the same line or logically on the same line?
    <%response.setHeader ("Content-Disposition","attachment;filename=xxx.txt"); %>
    <%@ page import="java.sql.*" %>
    <%@ page extends="someone.taglib.servlet.MyDialogServlet" %>
    <%@ page contentType="application/save; charset=iso-8859-1" language="java" import=""%>
    <%@ page import="MyProductBean" %>
    .....body of JSP........
    Thanks so much!

  • How to enable downloading of an Attached File at the Client End

    Hi
    In the process of enabling File Attachment in my Email Service (using Servlets), I have been able to upload the file chosen for attachment.
    Now I am facing the following 3 problems :-
    1. How to enable the client to download his file from his broser ?
    2. How to provide features of uploading multiple files, as till now i have been able to upload only a single fiel ?
    3. I don't want the files to be uploaded as soon as i press upload. Instead I want all files to be collected in a list box and then be uploaded together when i press Attach.
    If anybody has any information, then please send that ASAP.
    thanx

    go there
    http://forum.java.sun.com/thread.jsp?forum=45&thread=155600

  • File download from back end syetem to the user system

    Hi,
    This is very urgent requirement for me, can anybody help me regarding this:
    I have back end on one system and the front end on a different system. The use has login from third system.
    There is file on the back end system. User want to download that file using FTP to the local system. The Ftp download class is available at the back end system. Can anybody help me in sending the request from JSP to the back end to download the file from back end to the user's local system. FYI, I have to use core JSP/Servlet - support jre 1.4.2
    Thanks and Regards,
    braj

    hi,
    i tested this for you and the following code works fine. tested it on my 10.1.2 instance.
    declare
    l_new_item_master_id number;
    l_caid number := 33;
    l_folder_id number := 34373;
    begin
    portal.wwctx_api.SET_CONTEXT('portal','manager1','');
    portal.wwctx_api.set_nls_language(P_NLS_LANGUAGE => 'e');
    l_new_item_master_id := wwsbr_api.add_item(
    p_caid => l_caid,
    p_folder_id => l_folder_id,
    p_display_name => 'portal.doc',
    p_type_id => wwsbr_api.ITEM_TYPE_FILE,
    p_type_caid => wwsbr_api.SHARED_OBJECTS,
    p_description => 'This is the text of the review.',
    p_file_filename => '/home/oracle/test/portal.doc');
    wwpro_api_invalidation.execute_cache_invalidation;
    end;
    regards,
    christian

Maybe you are looking for

  • Unable to print with my Canon PIXMA IP 4700 and JetDirect network appliance

    After many tries I decided to post my question. I have a Canon PIXMA IP 4700 connected to the network with a Jetdirect 175X box. So I tried to add a new printer with a "HP Jetdirect Socket" port. I have previously installed the driver from the offici

  • Cannot Print PDF File from IE8 Beta 2

    I recently installed Adobe Reader 9 and Internet Explorer 8 Beta 2 under Vista 32-bit. When a PDF file appears under IE8, I cannot print the file. The print command shows only a blank page. If I save the PDF file, open Adobe Reader 9 and open this PD

  • Ipf: trying to understand the syntax

    HI! I would like to configure my ipf and tryimg to understand its syntax. For example: pass in quick proto tcp from 129.97.0.0/16 to any port = 22 keep state and pass in quick on bge0 proto tcp from any to 0/32 port = 22 flags S keep state group 100

  • WAD error :: Uncaught exception

    Hi All, I am facing one problem with WAD report. When I drag and drop one characteristic with hierarchy into the report it is showing the following error:: Termination message sent ABEND RSBOLAP (000): Program error in class SAPMSSY1 method : UNCAUGH

  • Prices don't appear in prodcut details

    Hello, I'm working with a product in my b2b application. i used the procedure bellow  to affect a price to my product : SAP easy access->master data->Prices and condition. In application select CRM.In MaintenanceGrp select PRODPRICES When i created m