How to replace a line in file Java

Hi,
I want to replace a line in file sequencial.
I read file, but i don't know how to replace one line..
Thanks...

I supose this..
I usea a FileReader and BufferedReader to read a file.
I read a line, I know the number of the line, but how to say to method println o write what it's the line to replace?

Similar Messages

  • How to replace a line ina text file using java?

    Hi ALL,
    Does anybody know how to replace a line in a text file uisng java.

    use this thing:
    http://doesthatevencompile.com/current-projects/code-sniplets/ASCIIFile.htm
    open the file,
    read its contents, replace the text you need in the contents, set the contents back into the file.
    it takes care of the IO for you.

  • How to replace a line in a csv file

    Hi everyone,
    What i need to do is to write into a csv file, line by line. When I'm in the line #1000, I need to go back to line #1 and replace the old line by a new line.
    I only found a way to do this but I don't think it's a good way.
    I read the actual file, I put it in an array (with spreadsheet string to array), I replace the text in the specific index of the array, I delete the old file and I convert the array to a spreadsheet string and then write it in a new file. It's strange but it works. Is there any other (smarter) way to do this?
    Thank you
    Stéphanie

    Peachy wrote:
    Unfortunatly, I can't have the same length on every line. I don't know what's going to be witten in the text.
    Unfortunately, in this case you cannot really do what you want. Whenever you replace a line, all bytes to the right need to be shifted up or down to account for the change in length. A file is just a long sequence of bytes and a line break is just the presence of a newline character. There is no concept of "lines" per se.
    LabVIEW Champion . Do more with less code and in less time .

  • How to replace bytes in a file?

    How to replace some bytes in a file without rewriting it entirely?
    bye
    aldo

    I repeat my question:I repeat my answer...
    java.io.RandomAccessFile.
    Have a look at the java doc!

  • How to write single line text file

    Hi, I need to write a single line text file using oracle forms 10g that's usually quite long 8million+ characters, I looked into utl_file but came accross the single line limit, is there any way to do this either to the client pc or to the server
    Thanks

    I tried using put_line but i get a ORA-29285: file write error´I´m guessing this is because of the amount of data to be written on a single line

  • How many number of lines of code Java File can have?

    Hi ALL
    Is there any limit on java source file code length?
    does more code (say more than 4000 line) impact on performace?
    Is there any recomendation on code length and file size?
    Thanks

    Hi ALL
    Is there any limit on java source file code length? There are some (VM) limitations but I have only hit that one when I had some generated code.
    does more code (say more than 4000 line) impact on
    performace?No, but you probably have a stupid design if you have 4000 lines in one file.
    Is there any recomendation on code length and file
    size?You should usually only have one top level clas per file, and you should try to have less than 1000 lines in one class.
    Kaj

  • How to replace a string in file

    if a file's content is:
    aaa 123 456
    bbb 341 343
    ccc 343 233
    now i want to replace 341 with 768
    how?
    & use which classes? thx!

    I would suggest
    java.io*;
    Use a beffered Reader, read the file, and output into another one

  • How to create additional Line in file based on condition available as part of ZINVOIC02 Idoc segment

    Scenario Details:
    Receiving Zinvoic02 Idoc in PI. Idoc to file translation creates comma separated file with .csv extn
    The logic was kept in such a way that how many E1EDP01 (items) are available in IDoc that many no of records will be created in csv file.
    The file logic for some the fields is as below:
    No of records
    InvNumber
    InvDate
    CusNumber
    LineitemDesc
    Tax1Type
    Tax1%
    for 1st E1EDP01
    E1EDK01-BELNR
    E1EDK03-DATUM
    E1EDK01-PARTN
    Populate when E1EDP04/MSKWZ=O2 or O4 with E1EDP19/KTEXT
    Hardcode when E1EDP04/MSKWZ=O2 or O4
    Sum all E1EDP04 /MSATZ when E1EDP04/MSKWZ=O2 or O4
    for 2nd E1EDP01
    E1EDK01-BELNR
    E1EDK01-DATUM
    E1EDK01-PARTN
    same as above
    same as above
    same as above
    for 3rd E1EDP01
    E1EDK01-BELNR
    E1EDK03-DATUM
    E1EDK01-PARTN
    same as above
    same as above
    same as above
    Additional Line to be created when one or more of E1EDP01 is having E1EDP04/MSKWZ = O3
    same as above
    same as above
    same as above
    Hardcode "REIM for USE TAX"
    Hardcode ""
    Hardcode ""
    Now we have got addition requirement to add a new lineitem when tax code is equal to O3 for any of the E1EDP01.
    Is it possible to create additional lineitem based on condition. If yes, please share what should be the approach.
    How we can create the additional lineitem?
    Currently we are using E1EDP01 to do context handling.
    The target structure is :
    MT_FILE
         INVOICE     0..unbounded
              InvNumber     0..1
              InvDate          0..1
              CusNumber     0..1
              LineitemDesc     0..1
              Tax1Type          0..1
              Tax1%               0..1

    Hello,
    Please add one extra field in the data structure of the target mapping and let its occurrence be 0..unbounded under the root node 'MT_ADP_Invoice'.
    Apply the condition, if tax code MSKWZ (with its context changed to E1EDP01) equalsS to '03', then map it to the newly created target field whose occurrence is 0..unbounded.
    This will then create an additional field which is your requirement.
    The above is one way.
    But if you want to have the same target field name as ADP_File appended for tax field being '03'.
    Then in that case you can you two message mapping for one common operational mapping / interface.
    In the first message mapping you need to have one target data structure created with the source data structure remaining the same as the one shown by you in scrn shot. Now this target data structure will be similar to the source, except that you need to add one more field at the end(name different from other fields) in target (whose occurrence should be 0..unbounded), and it needs to be mapped to E1EDP01 provided the tax code field MSKWZ(its context changed to E1EDP01) equalsS to constant '03'.
    In the second message mapping you need to map the target structure of previous message mapping to the actual required structure. The newly added field should be mapped to ADP_File of your final target structure.
    This will then create the same structure as required.
    Note : Please change the occurence of ADP_File to 0..unbounded.
    Regards,
    Souvik

  • How to replace text in a file

    Hi everyone,
    I have a txt file and It has some data's. I want to specifically replace a character in the text file. Data's will be like this,
    TT=15
    S1ST=21601
    S1EN=50400
    S2ST=50401
    S2EN=72000
    S3ST=72001
    S3EN=21600
    GNST=00000
    GNEN=00000
    S1B1S=22800
    S1B1E=23400
    S1B2S=28800
    S1B2E=30600
    S1B3S=36000
    S1B3E=36600
    S1B4S=45000
    S1B4E=46800
    In the 2nd line i.e. S1ST=21601, I want to replace 36000 instead of 21601.
    After replacing the specific character, data's should overwrite in the file or appending the file will also ok for me.
    Give me a suggestion. I am using LV 8.2. So plz post your code in 8.2 ver
    Thanks in advance.
    Regards,
    Vijay
    Solved!
    Go to Solution.

    Check this out.
    Edit:- attaching 8.2 version
    With Regards
    Miraz
    Kudos is better option to thank somebody on this forum
    Attachments:
    String.vi ‏8 KB
    String.vi ‏8 KB

  • How to handle blank line in File adapter

    Hi,
    I am using a file adapter with CSV as input file. If I have a blank line in CSV file, BPEL is failing read it, no instance is created and file is archieved.
    Please let me know how to handle this issue.
    Thanks

    Hi Yatan,
    I am already using rejectedMessageHandlers, I am on 10.1.3.3.
    Here's my bpel.xml
    ============
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <BPELSuitcase>
    <BPELProcess id="EmpAddressUpdABCSImpl" src="EmpAddressUpdABCSImpl.bpel">
    <partnerLinkBindings>
    <partnerLinkBinding name="ReadFile">
    <property name="wsdlLocation">ReadFile.wsdl</property>
    <property name="rejectedMessageHandlers">file://E:/HRARCHIVE/BadData</property>
    </partnerLinkBinding>
    <partnerLinkBinding name="InsertAddressUpd">
    <property name="wsdlLocation">InsertAddressUpd.wsdl</property>
    <property name="retryInterval">60</property>
    </partnerLinkBinding>
    </partnerLinkBindings>
    <configurations>
    <property name="sensorLocation">sensor.xml</property>
    <property name="sensorActionLocation">sensorAction.xml</property>
    </configurations>
    <activationAgents>
    <activationAgent className="oracle.tip.adapter.fw.agent.jca.JCAActivationAgent" partnerLink="ReadFile">
    <property name="portType">Read_ptt</property>
    <property name="rejectedMessageHandlers">file://E:/HRARCHIVE/BadData</property>
    </activationAgent>
    </activationAgents>
    </BPELProcess>
    </BPELSuitcase>
    Someone told me that this can be achieved by changing the native schema, I tried many options but no result. Please suggest me.
    -- Shirish

  • How to replace a line segment?

    Here's what I want to do:
    Take the selected line segment, and replace it with a series of line segments, scaled to the length of the line.
    I'm not quite sure how to go about this.  I don't see any line object relating to a path item.  All I see are anchors.  I know I can access the two anchors of the line segment that's selected, but to begin with, how to I delete the line connecting the anchors?

    Here's an image to help illustrate.  The object on the left has a line segment selected.  The script runs and removes the segment, then replaces it with the door path, scaled up to the correct width to fit:

  • How to ignore particular lines in File Adapater

    Hi ,
    We are aware we can ignore the comments in the begning of the file by putting the document offset in the sender adapater
    but is there a way we can ignore comments if the occure in the middle of the line
    like if my i/p file is like
    transactionId=3c68ffae-10d61001cd5
    uniqueId=3c68ffae-10d61001cd5
    Wed Aug 30 21:33:20 UTC 2006
    recordindex=0
    broker_domain     broker_org     Accepted With Changes     29Aug2006110525     4500000020     $null     29Aug2006110525     Discrete_Order     0000352119     vendor1     SSP_CUSTOMER     SSP_CUSTOMER     $null     $null     $null     $null     $null     $null     $null     $null     $null     $null     $null     $null     $null     0001     $null     $null     $null     $null     $null     29Aug2006000000     $null     $null     $null     $null     $null     10     S107999436     Test Material created on 29 August 2006     SSP_CUSTOMER_domain     S107999436     Test Material created on 29 August 2006     0000352119_domain     100000.0     $null     EUR     EA     Accepted With Changes     29Aug2006110525     29Aug2006110525     S107999436     $null     $null     $null     $null     $null     1     Sup_Change_UI     Accepted With Changes     29Aug2006110522     500.0     29Aug2006000000     29Aug2006000000     500.0     29Aug2006000000     $null     $null     $null     5302     $null     $null     $null     $null     $null     $null     $null     $null     29Aug2006110522     $null     $null     $null     $null     $null     $null     $null     $null     $null     $null     $null     $null     $null     1     $null     $null     $null     $null     $null     $null     $null     $null     600.0     29Aug2006000000     $null     $null     $null     $null     $null     $null
    recordindex=1
    broker_domain     broker_org     Accepted With Changes     29Aug2006110525     4500000020     $null     29Aug2006110525     Discrete_Order     0000352119     vendor1     SSP_CUSTOMER     SSP_CUSTOMER     $null     $null     $null     $null     $null     $null     $null     $null     $null     $null     $null     $null     $null     0001     $null     $null     $null     $null     $null     29Aug2006000000     $null     $null     $null     $null     $null     10     S107999436     Test Material created on 29 August 2006     SSP_CUSTOMER_domain     S107999436     Test Material created on 29 August 2006     0000352119_domain     100000.0     $null     EUR     EA     Accepted With Changes     29Aug2006110525     29Aug2006110525     S107999436     $null     $null     $null     $null     $null     2     Sup_Change_UI     Accepted With Changes     29Aug2006110522     500.0     30Aug2006000000     30Aug2006000000     500.0     30Aug2006000000     $null     $null     $null     5302     $null     $null     $null     $null     $null     $null     $null     $null     29Aug2006110522     $null     $null     $null     $null     $null     $null     $null     $null     $null     $null     $null     $null     $null     1     $null     $null     $null     $null     $null     $null     $null     $null     400.0     30Aug2006000000     $null     $null     $null     $null     $null     $null
    I dont want to read lines with #
    Is there a way we can achieve this
    Thanks
    Amit

    Hi,
    Could you also try using the conversion agent to handle this type of problem ?
    Only a thought.
    http://help.sap.com/saphelp_nw04/helpdata/en/14/80243b4a66ae0ce10000000a11402f/frameset.htm
    Kind regards
    Colin.

  • Replace line in file

    Hi,
    does anybody know how to replace one line in a file with another line? I want to change only one line in a file and do not know how i can do it.
    Greetings.

    Would both the old and new lines be the samelength?
    No, they differ in length.Then you can't do it without create a whole new file.
    Read the old file.
    Spit the content of the old file into a new one.
    When you get to the line you want to change put the new line in instead of the old one...
    Continue on copying the lines from old to new.
    You CAN replace content in a file but if they have different length's you are SOL.

  • How to eliminate empty lines in Flat file.

    Hi All,
    How to delete the empty lines in flat file,i am explaining below with data
    Here we have 3 fields with field lengths 30,10,34  i am checking the condition in message mapping if the middle field containing 9999999999 i am deleting the total record but in output file i am getting empty line how to eleminate empy lines in file please suggest me is it possible through Content Convertion.
    Thanks,
    Sudheer.
    0500189175247200000500003141700000142888073108000009640566210000
    0500189175247200000500012449050000142889072908000009623017230000
    0500189175247200000500000496210000142890073008000009631840760000
    0500189175247200000500000162130000142891072808000009613028730000
    0500189175247200000500001356750000142892072908000009621443430000
    0500189175247200000500012982910000142893072908000009622158440000
    0500189175247200000500001380990000142894073008000009631876720000
    0500189175247200000500000074560000142895072808000009613904430000
    0500189175247200000500003351650000142896072908000009623005030000
    0500189175247200000500000061170000142898072808000009613026140000
    0500189175247200000500000060590000142900073008000009630862400000
    0500189175247200000500000155320000142901072908000009623234640000
    0500189175247200000500043425220000142903072808000009612752160000
    0500189175247200000500000517450000142904073108000009640911680000
    0500189175247200000500006901140000142905073008000009630927540000
    0500189175247200000500001565590000142906073008000009630938540000
    0500189175247200000500000210440000142907073108000009640765850000
    0500189175247200000500000187500000142908072908000009622980650000
    0500189175247200000500000069240000142909072908000009622980660000

    Hi,
    I think we could handle this with may be usage of Advanced UDF in Graphical mapping only.
    Here as per the condition you are deleting the particular record but unknowingly blank value i.e. " " is getting passed so on target side blank node is created for this record.
    You need to just avoid this blank Node.
    If you can share the logic you have applied for Middle field as well the source and target structure I will be able to try the UDF code..based on it
    Thanks
    swarup

  • How to sync writing to a file?

    Hi all,
    I'm implementing a simple line logger for my web applications.
    Basically, I have some class with a "write" method, that appends a line of text into a certain file.
    All of my web apps log into the same file (by design).
    How do I make sure writing to the file is synchronized?
    The web apps cannot share logger objects between them (not even singletons, correct?) so using the 'synchronized' qualifier for the 'write' method won't work because each web app has its own instance of the logger object.
    Also, FileLock won't work since all web apps "live" inside the same JVM (accoding to javadoc, FileLock is not suitable for syncing file-writes by different threads within the same JVM).
    I've looked up the forum for answers to these questions, but non of the threads on this topic provided any leads...
    Any ideas?

    hii...
    can sum1 plz tell me how to replace bytes in a file?
    i've used randomaccess to open the file....read is
    contents and write back to it at the desired
    locations using seek()...however at some position if
    i wish to read the data and replace it with new data
    at exactly the same location...how can i do it??
    bye.i had already mentioned my problem....actually i want to read a record from a file and then update it at the same location in the file...so i need to replace it(or delete the record and re-write the new info).

Maybe you are looking for

  • Part1 is not updating in  J1IEX

    Dear Experts, I am  posting GR  for import po,  in the excise tab  all the excise duties are visible in MIGO  I am updating RG23A Part1 through J1I5, system is giving me message records successfully processed,but when I am capturing excise invoice th

  • Says camera not supported

    Hi! have the adobe creative suite 5.5: Master collection and I own a Canon EOS rebel SL1.  I downloaded the camera raw plugin but it won'tl et me take my photos into photoshop. Its says my camera is not supported but on the camera list it is. I need

  • Tables for Target Group

    Dear experts, I have been looking for the table that stores the target group. Could anyone please help? thanks Mehmet

  • WCS is facing instability 4.1.83.0

    We have WCS 4.1.83.0 is installed in 2003 Server but nowadays the same is instable, When we done some analysising and found that "Wireless Network Management Application" was stopped and we were not able restart it. There is no problem with OS as wel

  • Photoshop Extended upgrade

    Can you upgrade from CS4 to CS6 Extended ?