Delete a character in a file

i have to delete a single char in a txt file. i'm working with this method:
public static void remChar(File inFile, char charToRem) throws IOException{          
if (!inFile.exists()) return;
BufferedReader in = new BufferedReader(new FileReader(inFile));
PrintWriter out = new PrintWriter(new FileWriter("/newFile.txt"));
String line = null;
while ((line = in.readLine()) != null) {
     int i=0;
     char[] check = line.toCharArray();
     while (i!=check.length-1) {
if (check==charToRem) {
     int j=0;
     for (j=i;j<check.length-1;j++)
     check[j]=check[j+1];
     line = check.toString().substring(0,line.length()-1);
     i++;
     else
     i++;
out.println(line);
out.flush();
out.close();
in.close();
but with this code i always receive a java.lang.StringIndexOutOfBoundsExeption: String index out of range.
How can i correct this code? Thank you!

this is one most easily understandable program. Kindly note that there are more methds to achieve the results, i am posting the most simple one as far as i know:
public class StrDelete
  public static void main(String[] args) throws Exception
    char srch='a';
    File f=new File("temp.txt");
    byte[] bt=new byte[(int)f.length()];
    FileInputStream fis=new FileInputStream(f);
    fis.read(bt);
    StringBuffer sb=new StringBuffer(new String(bt));
    System.out.println("The old content is:\n");
    for(int i=0;i<sb.length()-1;i++)
     if(sb.charAt(i)==srch)
     System.out.print(sb.charAt(i));
     sb.deleteCharAt(i);
     else
     System.out.print(sb.charAt(i));
    fis.close();
System.out.println("\n");
   System.out.println("The new data is:"+sb.toString()+"\n");
   FileOutputStream fos=new FileOutputStream(f);
   fos.write(sb.toString().getBytes());
   fos.close();
}

Similar Messages

  • How to delete the record in the file present in the application server?

    Hi,
      I have two questions.
      i) How can I delete a record based on some condition in the recordx in the file that is present in the application server?
      ii) How can I lock the users whiel one user is accessing the file on the application server?
    Thanks in advance.
    Suvan

    Hi,
    If u want a frequent deletion this approach to delete a record from a file will havee unnecesary copy of records from one file to another and deletion of one file and renaming activities.
    Instead what u can do is Add and field del_flag to ur record structure.
    If u want to delete the record from a file just mark this del_flag as 'X'.
    While processing u can have a loop like
    loop at it_XXX where del_flag <> 'X'.
    endloop.
    This will logically delete the record.
    When u r to finish the application at that time only perform this copying / deleting / and renaing activity
    Hope this helps.
    Cheers,
    Nitin

  • Trying to delete iPhoto 6 thumbsegment.data files crashes Mac OS 10.4

    Summary:
    Whenever I try to delete any of the thumb files from the iPhoto directory on my internal hard drive or my external backup drive, it crashes the computer (screen scrolls dark then says "Have to restart, hold button for several seconds" in multiple languages). This is true if I try to delete any single file or if I try to delete all the files (thumb32segment.data, thumb64segment.data, thumbJPGsegment.data). The panic message is:
    panic(cpu 0 caller 0x00102854): jnl: transaction too big (1582592 >= 1572352 bytes, bufsize 8192, tr 0x2733f7c bp 0x280286d0)
    The actual "transaction too big" numbers can vary. All my software is current as of last night. I'm running 10.4.6 and I have 150G drive with +10G free space, 1.25 GHz, 1GB memory.
    Background:
    I'm one of the people who experienced the extraordinarily sluggish version of iPhoto 6. In trying to fix it, I rebuilt my system from the hard drive up (including reinstalling everything)--no good. Apparently it was a known bug, a fix came out and my world was better. Until I tried to back up iPhoto.
    I back up to an external hard drive by dragging and dropping.
    1) Once I was sure the patch worked, I dragged the iPhoto folder from my internal drive to my backup drive...and the system crashed.
    2) Figuring it was the old, buggy version causing the problem I dragged the old, external backup iPhoto folder to the trash and tried to empty the trash...and the system crashed.
    3) After a file-by-file test, I determined it was the initial 2 thumbs (thumb32 and thumb64) from the buggy version causing the problem. One of the reasons I pay the Mac premium is because I don't want to be a sys admin, but nonetheless I went to Ihnatko's Mac OS X book and found the sudo command for forcing the trash to empty files (sudo chflags nouchg ~/.Trash/*), executed the command, emptied the trash...and the system crashed.
    4) So I moved the old thumbs into a different folder on my external drive and dragged and dropped a backup. No problem. Until I tried to do it a second time after my next update to iPhoto and...the system crashed.
    So now I have:
    * old external backup (thumb32, thumb64)
    * new external backup (thumb32, thumb64, thumbJPG)
    * new internal source (thumb32, thumb64, thumbJPG)
    and I can't backup or delete any of these files without the system crashing.
    Does anyone have any ideas how I can get rid of the extraneous thumb files and get back to doing a simple drag-and-drop backup without crashing my system? (And yes, I've learned my lesson not to be an early adopter of iLife...but that doesn't help me now.)
    FWIW, I'm having another problem with iPhoto or iTunes/iPod whereby iTunes/iPod has stopped recognizing iPhoto albums (http://discussions.apple.com/thread.jspa?threadID=530034&tstart=0). This happened long after the problem I've described here, but I'm including the link in case it's helpful.
    G4   Mac OS X (10.4.6)  

    Good morning Old Toad.
    I did as you suggested:
    1) Booted from install CD.
    2) Ran Disk Utilities on internal hard drive--no repairs necessary. For good measure, did the same thing on external drive. Also no repairs necessary.
    3) Checked software update--no updates found. About this Mac said I was already running 10.4.7. For good measure, I downloaded the latest and installed it. Since it let me run the install, I'm not sure if I installed something new or reinstalled what I already had.
    4) I rebooted from CD, ran disk utilities, ran repair disk--no repairs necessary. Repaired permissions and a lot of permissions repaired.
    5) Tried to delete the files and the same old thing happened: kernel panic. The specific message:
    panic(cpu 0 caller 0x00102A08): jnl: transaction too big (1587712 >= 1572352 bytes, bufsize 8192, tr 0x29f1fb0 bp 0x2801de40)
    So there's no change in my status.
    I'm trying to delete the files because:
    A) They already take .5 Gb.
    B) I can't get rid of them ever. If I move the problem files to a different folder, I can only do one successful drag-and-drop backup to the external drive until the "new" thumb segments become unerasable just like the previous versions and crash the system.
    C) I can't even "just" drag and drop every file/folder except the thumbs, because that ends up crashing the system as well. So I have to drag and drop every file/folder in the iPhoto hierarchy individually. Which makes me less inclined to backup, which defeats the purpose of a backup.
    D) After the iPhoto fiasco I'm just crabby about all the Apple screw-ups I'm experiencing and I want to get them fixed.
    Thanks for your help. Any additional suggestions would be appreciated.
    G4   Mac OS X (10.4.6)  

  • How to delete multiple old ITUNES LIBRARY files safely ?

    I'd like to clean up my Itunes LIBRARY files, but don't know what's safe to do and not to do. (I have Itunes 8.1 / OSX10.4.11)
    MY QUESTION IS TWOFOLD :
    (1) how do I create a new Itunes library file now with today's date; and
    (2) how do I delete multiple (old) Itunes library files, without risking the loss of what I've got ?
    This all stems from exploring Itunes as a result of a problem I had today... when trying to import mp3's from my terrabyte drive, after about 150 successful mp3 track imports, Itunes froze and everything else on my MAC froze as well (constant spinning colored wheel). After many failed attempts to force quit Itunes, I turned off my MBPro. On restarting, Itunes tooks ages to "import" files. Eventually Itunes opened but with only half of my original tunes (1500+ songs 8.11GB) and had nothing from today's import.
    I found a post suggesting to hold down OPTION while starting Itunes. Then I selected a file from my hard drive > me > music > Itunes > "Itune library" with the most recent date and shezam, Itunes once again has all my songs, as before. Nothing I imported from the terrabyte drive today appears however, but no matter.
    In my "Itunes" file there appear MULTIPLE Itunes libraries ! such as Itunes library, Itunes Library (damaged), and as well a folder called "Previous Itunes Libraries" which itself contains multiple Itunes Library files and multiple "previous Itunes Library files" with dates back to 2007. These I want to clean up and delete .... should I ? ... Can I ?
    I really could use some words of wisdom from the wise ! Thanks in advance

    Whenever you install a new version of iTunes and run it teh first time, iTunes will create a backup of the current iTunes library file and copy it into \Music\iTunes\Previous iTunes libraries, then update the iTunes library file in \Music\iTunes\ for the current version of iTunes.

  • Search Remote Files... or ...How Do I Delete All of My LCK Files?

    hey everyone.
    i need to delete a bunch of .LCK files from my server so
    Dreamweaver
    will stop telling me someone else has stuff checked-out and
    that i need
    to enable blah blah blah. i can't just check everything in
    because A.
    that would take forever and B. the "person" who has them
    checked out is
    actually me, from a previous site definition that is now gone
    because i
    had to recreate it.
    unless i'm missing something (and i've been spending some
    time looking
    for it), there doesn't seem to be a way in Dreamweaver (at
    least in
    version 8, which is what i have) to search for files on the
    remote view.
    and even if there was, it doesn't look like the remote view
    displays
    hidden files, i.e. .LCK files.
    my server control panel does give me the option to search for
    files
    using the file manager, but it only searches the folder you
    have
    selected, and no sub-folders. there are hundreds, maybe
    thousands of
    folders on this thing, and it would really take a long time
    to click on
    each and every folder, search for the .lck files, and then
    delete them.
    so, my question is, what would be the best/easiest way to
    find and
    delete .lck files (or really, any file for that matter) on
    the remote
    server?
    thanks!

    i do NOT want check-in/check-out enabled. i'm trying to get
    rid of it
    altogether, but i tried selecting the checked out files to
    check them
    back in, and it said there were none.
    there is no "unlock" option, so i guess i need to pick check
    in. but
    here's my question, since it's this other instance of "me"
    that has them
    checked out, will this work? it's not recognizing me or my
    computer or
    whatever as the person who has them checked out. i think it's
    because i
    had to recreate my site definition about a week ago or so,
    and i deleted
    the old one. so it's like a user that no longer exists has
    them checked out.
    Alan wrote:
    > Do you want checkin/checkout to still be enabled when
    this is done?
    >
    > try this or a variation of it-
    >
    > in the Files Panel, right-click on the root site folder
    and pick checkin. Or
    > unlock.
    >
    >

  • In making a "highlights" movie, using clips from different imported iMovie events, can I delete the larger iMovie event file from the Events browser and still work w the smaller clips in the Projects browser w/o having the larger files still loaded?

    I have sucessfully imported 150 Sony digital 8mm movies (each one hour in length) into iMovie as 150 iMovie events. I have since successfully converted them from their original 13 Gb (.dv) file to an exported smaller 1.3 Gb (.4mv "large file") movie that I am happy with, using the iMovie projects browser. So now I have 150 " .4mv" movies on my internal HD as well as about half of my original raw data " .dv " movies on my internal hard drive.
    Due to their large size (over 2 Tb), I do not have all the larger raw data (.dv) files on my 2Tb internal drive, just about half of them. What I want to do now is to create a new project in the Projects browser for each of my kids, and reload, starting with Tape #1, each of these larger files and do a highlights movie for each of my kids, wherein I pick out smaller clips from each 1 hour .dv iMovie event and paste them into the appropriate kid's Highlights project in the Projects browser.
    Here's my question: If I load the first 5 large files back onto my internal HD, and paste in various shorter clips into each of my kids' Highlights project, and then if I delete those first 5 large files (they are backed up on 2 other 3Tb external HDs), can I keep doing this (reloading the next 5 large .dv files to work with), and ultimately take each of my kid's Highlights project and export as a .4mv movie EVEN THOUGH the earlier large .dv files are no longer on my internal HD, OR does my iMac need to have all these larger files loaded on my internal HD for me to eventually export each of my kid's Highlights project to a .4mv movie?
    I have a 2011 era 27" iMac desktop w 2Tb HD internal and 250 Gb flash drive, and Lion OSX and iMovie 11.

    Thanks. I tested it out and you were correct. I loaded 2 .dv movies from my external HD back onto my internal HD, and got them re-imported into iMovie, took a few short clips from each of the 2 iMovie events and pasted them into a new project in the Project Browser. Then I deleted these 2  "source clips" from my internal HD, closed iMovie and then re-opened it and found that iMovie would NOT export the smaller clips for a "highlights" .4mv movie without the "source clips" being available.
    I read your link on Quicktime. It talks about mostly trimming, which is what I did with each iMovie event before I took each one as a project to export as a smaller .4mv file. But if I use Quicktime (do I need QT Pro or basic), what advantage is it to me to use QT over iMovie (I must admit I am a novice at iMovie and have never used QT or QT Pro as a tool)? Will it then convert any edits I make to a .m4v movie or do I need iMovie to do that?
    Does QT allow trimming multiple segments out of a movie during one edit session, or can you only do 1 at a time? By that I mean that, for example, when I use Sonys Picture Motion Browser for my .mts movies, you can only set one Start and one End point for each edit/trim you do: it does not allow you to set multiple Start Stop points like iMovie allows in its Event or Project browser. You can only do one "trim" at a time, save it and then reopen to do another trim. not very useful.

  • Delete data from a flat file using PL/SQL -- Please help.. urgent

    Hi All,
    We are writing data to a flat file using Text_IO.Put_Line command. We want to delete data / record from that file after data is written onto it.
    Please let us know if this is possible.
    Thanks in advance.
    Vaishali

    There's nothing in UTL_FILE to do this, so your options are either to write a Java stored procedure to do it or to use whatever mechanism the host operating system supports for editing files.
    Alternatively, you could write a PL/SQL procedure to read each line in from the file and then write them out to a second file, discarding the line you don't want along the way.

  • I am trying to delete pages from a PDF file. I opened the bookmarks, selected the pages to delete and choose Edit Delete. The selected pages are not deleted. Note: I have to open the file using a passport provided by an external party.

    I am trying to delete pages from a PDF file. I opened the bookmarks in the PDF file, selected the pages to delete and choose Edit > Delete. The selected pages are not deleted. Note: I have to open the file using a passport provided by an external party.

    Resolved

  • How to delete the specified line in file?

    How to delete the specified line in file? In case of deleting a specified line in a file, how to do?
    Line 1
    Line 2
    Line 3
    Line 4
    Line 5
    The case is a file including the above content. Now I wanna to delete the "Line 3" and how to realize the action in Java?

    An alternative solution can be :
    import java.io.LineNumberReader;
    import java.io.IOException;
    import java.io.File;
    import java.io.FileReader;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.PrintWriter;
    public class LineDeleter {
    public static void main(String args[]){
    try {
    //suppose you want to delete line 3
         int lineToBeDeleted = 3;
         File f = new File("line.txt");
         long fileSize = f.length();
    //Wrap the FileReader with a LineNumberReader. It will help you
    //identify the lines.
    LineNumberReader lnr = new LineNumberReader( new FileReader(f));
    //Wrap the FileWriter object with BufferedWriter object. Create it with the buffersize
    //equal to the file size.
         BufferedWriter bw = new BufferedWriter(new FileWriter(new File("line1.txt")),(int)fileSize);
    //Wrap BufferedWriter object with PrintWriter so that it allows you
    //to print line by line
    PrintWriter pw = new PrintWriter(bw);
         String s=null;
         while ( (s=lnr.readLine())!=null ){
              System.out.println(s);
              int lineNumber = lnr.getLineNumber();
    //match the line number
              if(! (lineNumber==lineToBeDeleted)){
                   pw.println(s);
              pw.flush();
              lnr.close();
              pw.close();
         catch(Exception e){System.out.println(e);}
    If you want you can rename the line1.txt to the original file name.
    I hope this helps.Good luck!!!!!!

  • How do I batch delete all my protected music files from iTunes.

    Hi, in a moment of stupidity, while I was working on a backup folder of my friends files (from his broken computer - copied them to my PC so he could get them back onto his new PC) I managed to copy all of his songs from his iTunes folder into my iTunes library. I don't know how I managed to do this, maybe it was the fact that I was really tired at the time.
    I own all my music - none of my music is copy protected (it is either downloaded from legal sites where the bands themselves [usually unknown or alternative artists] release their music, or I ripped the music from CD's I bought) and all of his music is copy protected.
    Now thing is, I have upgraded my PC before realising I did this, so now I don't have the original iTunes library (formatted PC and reinstalled XP from scratch) - is there any tools out there that will find and delete all your copy protected files from iTunes?
    I could go through song by song and when it comes up with the "Authorise computer - This computer is not authorised to play "******" Would you like to authorise it" and delete those songs, but as this is a very slow and time consuming process and considering I have 8,551 songs, I would prefer a faster way.
    I would go and re-rip all the songs, as I have the original discs, but this would take very long, and put quite a bit of strain on my CD drive, and this would not account for all the songs I have spent years finding on the internet/demo songs from friends bands.
    Any help is appreciated, as I would love to be able to remove all of his songs so they don't keep popping up in my iTunes library
    Thanks in advance.
    Dale.

    I have never tried this and am not at a computer with iTunes, but can you delete from a Smart Playlist? If so, you could make a smart playlist that shows songs that are of kind Protected ACC. Then select all and delete from that playlist. But I am not so sure if you can delete from a smart playlist.

  • How do I delete a character tag so it does not continue to show up in my designer.

    Hello.
    I have deleted a character tag from the catalog but it keeps showing up in the designer and stays associated with any new paragraph tag I try to create. How can I set the character designer to blank?
    Thanks

    >System Preferences>Mission Control>Show Desktop...should be F11:
    If not, change it.

  • Delete a character at a time from a textarea

    I am designing a mobile phone simulation, where the user creates a message from a keypad, to the text area, there is a back button that does two things:
    1. Deletes a character at a time
    2. Moves back through text
    How do i delete a character at a time //
    I thought about doing a count of the text in the text area then use delteCharAt() and give the position as count, but it requires the variable to be a StringBuffer and mytextarea variable is of type string, this is what i have done but it does not work any suggestions please.
    int count = 0;
    System.out.println("pressed BCK");
    txtmsg = (display.getText());
    count = txtmsg.length();
    System.out.println(count);
              if (e.getSource()==keys[9])
                   System.out.println("pressed BCK twice - DELETE");
                   txtmsg.deleteCharAt(count);
                   display.setText(display.getText());
              }Thank You

    When i do this i get the following error, cannot find symbol method deleteCharAt().
    Txtmsg is of type string, don't know if this matters.

  • Looking for a program to delete CVCs from a flat file, infocube, ztable.

    I am looking for a program that will delete CVCs from a flat file, infocube, or ztable. Based on the research I have done, I would imagine the core of such a program would be the use of function module /sapapo/ts_plob_delete.
    If anyone has such a program and would be willing to share it that would be great.
    Shane

    Hi
    Yes you can use this program, but I think the program /sapapo/ts_plob_delete will only delete the data from Master planning Object structure( MPOS). First you have to deactivate the planning are first than use this program which will delete everything and again activate the planning area.
    If you want to delete the data flat files or infocube, you require to delete the data directly from the infocubes and add this job in the process chain to delete everything.
    I hope this information help you.
    Thanks
    Amol

  • How to deal with special character in source file

    Hi experts,
                      i am doing a file to file scenario in which my source file contains many special characters when i am puting this file into moni its going with the special character .My source file is a fixed length file so in content conversion i have specified the file length but due to these special charcters these field lenght is also varing.So please guide me how to deal with these special characters in sender adapter
    regards,
    Saurabh

    you could try using a Java Mapping to change the encoding manually. For that, set the encoding of the OutputFormat of the XML you'll serialize. Try the following code piece for the mapping (inside a try/catch declaration):
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = factory.newDocumentBuilder();
    Document input = documentBuilder.parse(in);
    OutputFormat format = new OutputFormat(XML, "ISO-8859-1", false);
    XMLSerializer serializer = new XMLSerializer(out, format);
    For more details check this guide:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/uuid/502991a2-45d9-2910-d99f-8aba5d79fb42

  • Delete pages in my .pdf file and save as another file?

    Just purchase the subscription to a year worth of converting files to word/excel.  However, the conversion isn't accurate and I only purchase this to enable me to delete pages in my pdf file that I don't want...

    Hi,
    To delete page(s) in PDF file:
    1. Open your PDF file in Acrobat
    2. Select "Tools" from right top corner of the document windows
    3. Select " Manipulate Pages"
    4. Select "Delete".
    You can download Acrobat XI Pro trial version from www.adobe.com
    Hisami

Maybe you are looking for

  • Error while running simple JAXB test class

    I am new to JAXB and trying to run simple tutorial code. I created Java project and added required jar files in a classpath. But I get error as "com.jaxbtest" doesnt contain ObjectFactory.class or jaxb.index I am using Eclipse and I have added these

  • Reg: Creation of Dynamic Internal table

    Hi All, I got a requirement which should be handled by creating dynamic internal table. *Scenario: * 1.First I will fetch data from one table into an internal table. Let suppose I am fetching the fieldnames of the table MAKT from DD03l. Then I will h

  • Payment Batch

    Dears, Please note that we are grouping our invoices in batch number and this batch number is costumized and when we run concurrent request this number batch will be generated automatically in DFF so we are trying to pay these invoices under the batc

  • Scrolling image gallery problems

    I am creating a scrolling image gallery using thumbnails.  I have 36 thumbnails that are 100 x 100 px.  I cannot figure out the x y coordinates to line up the images correctly.  They are overlapping.  I've put in the first x coordinate at 0 and the f

  • Iphone no sound from speaker, headphones work

    Hello guys Suddenly my iphone5 speaker stopped working. No updates, no water, no fall. My headphones work and the bar of the music goes up and down. Any thoughts? Did anyone experience the same issue? Thanks in advance