Unable to insert properly the text in a already existing file

Hi Everyone,
I am trying to read and write the text file using randomaccess class.
When i am trying to update a line with string its over writing next line with the same number of bytes as my string which i am trying to insert.
For example if my text file has following data
test
most
must
if i try to insert "text" after "test" the program overwriting the "most" word.
if anyone can help that will be great. thanks in advance. Below is the code:
RandomAccessFile raf = new RandomAccessFile(aFile, "rw");
long len1 = raf.length();
long off1 = 0;
String line1;
boolean updated = false;
while ((line1 = raf.readLine()) != null)
int coma;
if ((coma = line1.indexOf(",")) != -1)
String s = line1.substring(0, coma);
if (s.equals(str))
line1.indexOf(",", coma);
StringBuffer nStr = new StringBuffer();
nStr.append(line1);
nStr.append(",");
nStr.append(str1);
nStr.append(System.getProperty("line.separator"));
raf.seek(off1);
raf.writeBytes(nStr.toString());
raf.close();

You can't insert data that way. You are always going to be overwriting data (unless you go past the end of the existing file, in which case you are going to be appending data).
If you want to insert data, here's what you have to do:
1. Write the data before the insertion point to a new file.
2. Write the data you want to insert to that new file.
3. Write the data after the insertion point to a new file.
4. Close the new file.
5. Delete the old file.
6. Rename the new file.

Similar Messages

  • TS3276 Hi.  Just started using Mac Mail on a macbookpro v10.6.8.  I tried to send a message with two excel (for mac) files attached.  One attached as a file, one inserted all the text into the message body.  Help?

    Just started using my Mac Mail program instead of web mail.  When I went to attach two pdf files, one attached as a file, the other inserted all the text into the body of the email message.  How do I get it to attach both pdf's as files?

    I think you're confusing two different things. If you attached PDF files and one of them displayed the PDF icon in the message window, that means it was more than one page. If you saw what appeared to be the actual document for the other PDF file, that means it's only one page and it's normal for it to display that way.
    However, I seem to recall there may (or should) be a button at the bottom-right of the message window that allows you to display those files as icons, even if they're one page. If not, there's a third-party addition you can use to add that feature:
    http://lokiware.info/Attachment-Tamer

  • How can i AppendText to richTextBox only if the text is new(different) from the text that is already in the richTextBox ?

    Code
    public void ScrollNews()
    listsext.Ext(page);
    combindedString = string.Join(Environment.NewLine, ListsExtractions.myList);
    richTextBox1.SelectAll();
    richTextBox1.SelectionAlignment = HorizontalAlignment.Right;
    richTextBox1.AppendText(combindedString);
    scrollerText = string.Join(Environment.NewLine, ListsExtractions.myListWithoutLinks);
    scroller1.TextToScroll = scrollerText;
    if (NewsLevels.newsLevel && NewsLevels.shouldStart)
    UpdateTextControls();
    scroller1.Start();
    NewsLevels.shouldStart = false;
    if (NewsLevels.newsLevel == false && NewsLevels.shouldStart)
    UpdateTextControls();
    scroller1.Start();
    NewsLevels.shouldStart = false;
    string[] rlines = richTextBox1.Lines;
    richTextBox1.SelectionStart = 0;
    richTextBox1.SelectionLength = rlines[0].Length;
    richTextBox1.SelectionColor = Color.Red;
    richTextBox1.Select(rlines[0].Length, rlines[1].Length + 1);
    richTextBox1.SelectionColor = Color.Green;
    RedColorAlert1();
    if (lines == null)
    label5.Text = "0";
    else
    label5.Text = lines.Length.ToString();
    The line is:
    richTextBox1.AppendText(combindedString);
    I'm calling this method ScrollNews every X minutes with a timer.
    The way it is now it will AppendText all the time. But i want it to Add the combinededString only if the text in combindedString was different from the text that is already in the richTextBox. Somhow to keep all the time the last text and compare it and
    if there is a new text then appen it.

    public void Scroll()
    listsext.Ext(page);
    combindedString = string.Join(Environment.NewLine, ListsExtractions.myList);
    richTextBox1.SelectAll();
    StringBuilder sb = new StringBuilder();
    sb.Append(combindedString);
    richTextBox1.SelectionAlignment = HorizontalAlignment.Right;
    richTextBox1.AppendText(combindedString);
    The problem is that now it will keep adding to the richTextBox the content in combindedString over and over again. I need somehow to check each time if the content in combindedString already exist in the richTextBox if not meaning it's new content then AppendText
    it.
    If it's the same already exist do nothing don't add it.
    EDIT
    I write to a text file the content of the ombindedString variable .The first content the lines is the combindedString:
    המשטרה עצרה אמא ל2 ילדים קטנים שבעלה נעצר בחשד למעורבות בעלה בכריתת עצים
    15:03 דווח במקור בתאריך : 09.03.15 : שעה
    http://rotter.net/forum/scoops1/189935.shtml
    אדם החשוד בעבירת מין בקטינים נעצר לאחר שהתלונן על 2 שסוחטים אותו על רקע מעשיו
    14:50 דווח במקור בתאריך : 09.03.15 : שעה
    http://rotter.net/forum/scoops1/189932.shtml
    אינדונזיה: 5 הרוגים בקריסת האנגר בנמל תעופה
    14:44 דווח במקור בתאריך : 09.03.15 : שעה
    http://rotter.net/forum/scoops1/189930.shtml
    אום אל-פחם: מספר חשודים עוכבו בחשד למעורבות במימון טרור
    14:04 דווח במקור בתאריך : 09.03.15 : שעה
    http://rotter.net/forum/scoops1/189914.shtml
    אלמנתו של רפ''ק ג'דעאן אסעד, שנרצח בפיגוע הדריסה, ילדה בן
    13:05 דווח במקור בתאריך : 09.03.15 : שעה
    http://rotter.net/forum/scoops1/189884.shtml
    תנאי ליברמן לכניסה לממשלה עונש מוות למחבלים חובת חתימה על מסמך נאמנות
    12:39 דווח במקור בתאריך : 09.03.15 : שעה
    http://rotter.net/forum/scoops1/189868.shtml
    תלמיד תיכון מרחובות חשוד שהפעיל מעבדה ביתית לזיוף תעודות זהות ואישורי מחלה
    12:03 דווח במקור בתאריך : 09.03.15 : שעה
    http://rotter.net/forum/scoops1/189856.shtml
    הצביעות של רענן שקד: האשים את אמהות 3 החטופים ומגנה את חגי הוברמן
    11:43 דווח במקור בתאריך : 09.03.15 : שעה
    http://rotter.net/forum/scoops1/189848.shtml
    And this is a screenshot i couldnt copy the text of the richTextBox1.Text
    richTextBox1.Text content image
    co uld be that the format of the text in the combindedString and the richTextBox1.Text looks different so it think it's not exist ?
    Update:
    Not sure if it's important but the combindedString i'm adding the text to it from the variable ListExtractions.myList
    myList is List and i build this List like that:
    private void ListToStringList(List<string> myl)
    for (int i = 0; i < AllNews.Count; i++)
    myl.Add(AllNews[i].text);
    IFormatProvider provider = CultureInfo.InvariantCulture;
    DateTime myTime = DateTime.ParseExact(AllNews[i].original_time, "DyyMMddTHHmm", provider);
    string results = myTime.ToString("HH:mm דווח במקור בתאריך : dd.MM.yy : שעה");
    myl.Add(results);
    myl.Add(AllNews[i].link);
    myl.Add(Environment.NewLine);
    myListWithoutLinks.Add(AllNews[i].text);
    myListWithoutLinks.Add(results);
    myListWithoutLinks.Add(Environment.NewLine);
    for (int i = 0; i < myl.Count; i++)
    myl[i] = Regex.Replace(myl[i], @"\t|\n|\r", "");
    And use it:
    ListToStringList(myList);

  • How to export the text edit data to excel file without splitting the data in excel file?

    how to export the text edit data to excel file without splitting the data in excel file?
    I have a requirement in SAP HR where in the appraiser can add comments in the area given and can export that to excel file. Currently the file is getting exported but the comments getting split into deifferent rows.
    I want the entire comment to be fit in one row.
    Please help.
    Thank you

    Hi,
    if your text edit value is stored in 'lv_string' variable.
    then before exporting the value to excel you have to remove CL_ABAP_CHAR_UTILITIES=>NEWLINE
    that is '#' from the variable lv_string.
    for that use code some thing like this.
    REPLACE ALL OCCURRENCES OF CL_ABAP_CHAR_UTILITIES=>NEWLINE in lv_string WITH space.
    I think this will do the trick.

  • The VAT registration number already exist while extending the CMR

    Hi All,
    We are already having a customer master record for two sales area(one for spain and another one for Netherland). Now we are extending the customer to a new sales area for the country Romania.
    But while extending  the customer we are getting the error message "The VAT registration number already exist".
    Awiting your reply.
    Thanks in advance.
    Sushanta

    Hi,
    Just make sure that your customer  basic country belong to the European Union. You need to select the OTHER Tab of the Vat Registration number . Enter Romania and its respective VAT number.
    Just try this and let me know if it working or Not.
    Regards
    Balachandar

  • The filename you entered already exists...

    When I attempt to save over an existing page (in order to
    replace it), I get the following error message:
    The filename you entered already exists. Please enter a
    different filename.
    How can a save over a file without being roadblocked by this
    error? Is it that Contribute is creating LCK files, and if so, is
    there a setting in Contribute that will prevent these LCK files
    from being created?
    Any suggestions?

    You or your administrator has to give you rights to delete
    files.

  • The table "WEBLOGIC.VISITORS_GS_CONTROL" already exists.

    Hi!
    I was just going through the "Getting Started" tutorials for WebLogic Workshop, and I got stuck at one point.
    I created a DB table, but there were some errors (didn't name one of the columns correctly), so the program couldn't run.
    I tried to fixed the problem, but when I tried to re-create the table, I got this error msg.
    <faultcode>JWSError</faultcode>
    <faultstring>The table "WEBLOGIC.VISITORS_GS_CONTROL" already exists.</faultstring>
    <detail>
    java.sql.SQLException: The table "WEBLOGIC.VISITORS_GS_CONTROL" already exists.
    at com.pointbase.net.netJDBCPrimitives.handleResponse(Unknown Source)
    I tried "cleaning" my projects, and also tried shutting down my server, but somehow I couldn't get rid of the "wrong" table that I have. Does anybody know how to do it?
    Thanks
    PS: I was doing the "Getting Started: Java Controls" tutorial

    Hello,
    Did you implemented the BrowseBy Property of your UDO form?
    If not, please do it, and you will be able to use the form. The BrowseBy should be connect to the ItemUID which contains the DocEntry Field of the @MyTable
    Use the following Query to check you entries
    select AutoKey  from onnm  where ObjectCode = 'UDO_NAME'
    UNION ALL
    select max(DocEntry) from  [@UDO_TABLE]
    Please check the following note about restoring functions:  752031 You can check help menu for the requested function........
    Regards,
    J.

  • Photoshop Elements 10 - 'Save As' text no longer displaying existing file, which matches the text so far entered

    Photoshop Elements 10  (On Windows 8.1 64-bit laptop)
    Until recently, 'save as' showed any existing file name, which exactly matched the text so far typed. 
    That's particularly useful when creating multiple photo files, with suffixes of '(1)', '(2)', etc.
    Suddenly that great facility has stopped, forcing me to always type the complete file name for each new item.
    I assume that a setting has been lost.
    How do I get it back?

    Thanks again.
    I held the keys down for at least 15 seconds in my previous attempts.  
    I’ve just tried the entries, holding the keys for around 30 seconds, with the same results (or lack of same).
    Thinking about my thought of copying the Preference settings from the same program on my desktop, I looked on the Internet for Photoshop Elements 10 Preferences file locations.   I found a display, which suggested:  C:\Users\user name\AppData\Roaming\Adobe\Photoshop Elements (9.0\10.0\11.0)\Editor
    From that, it appears that mine may be held in:
    C:\Users\Fred Niven\AppData\Roaming\Adobe\Photoshop Elements\10.0\Editor
    But I’m reluctant to copy any such file from my Windows 8.1 desktop’s Photoshop Elements 10’s file(s),
    to replace the equivalent file(s) on this laptop, until I know that I’m replacing the correct file(s). 
    I’d create a System Restore Point beforehand anyway, just-in-case.
    Cheers,
    Fred
    Fred's Footer

  • Field in portal table for the text contained in an uploaded file

    I have uploaded a file of base item type file into release 2 of the portal.
    Does anyone know which table the clob field for the text contained in
    the uploaded file is stored?
    Thanks,
    Suzanne

    Hi,
    When you run the Search hep is it giving the description or not
    You have to create the serarch help with both the fieldname and its description field then we cna the values. Or
    Try to mantain the text table for this field and get the data.
    Get the valeusinto drop drown with this table Or create the SearchHelp for this text table
    Regards
    Lekha

  • How can I copy the text on a published captivate file?

    I would like my students to use the content on the module by copying the text, how can i achieve it?
    Thank you.
    Weiwei

    My understanding is text in a SWF isn't really text any more, from the standpoint of it being mouse-selectable.
    If it is very limited instances of needing to copy text, you can use a text entry box and enter the text you want them to copy as the 'default text,' but it is far from being an ideal solution.
    There is a Text Area Widget included in Cp5.5 but it seems to be broken.  When I try to type random text in it to test, the text gets garbled with caps/lowers, and some letters don't show up at all when entered.  I typed "The quick brown fox jumped over the lazy dog" and it displayed as:  The uiC bron fox umeD oVer the lazy Dog
    There is a webpage widget that can embed a PDF or html page which you can to select the text, it might work for what you need but may take more back end work:  http://captivatedev.com/2010/11/05/adobe-captivate-5-web-page-widget/
    There maybe other included or availble widgets, I am by far not an expert with them.
    hope that helps.

  • Prevent Text Boxes to shrink as big as the text in it - move existing InfoPath form from SharePoint 2007 to SP2013

    Hello Together,
    we have some simple InfoPath forms in place. With SharePint 2007 they are working well. Now we will move to SharePoint 2013.
    It was easy to re-publish them on a SharePoint 2013 Site and to work with, but i have an optical / technical error and i don't find the solution.
    We use Text Boxes to collect the data from the user. After the user has filled the form we will submit them via mail.
    I will you show you the problem.
    on SharePoint 2007 --> it looks okay
    on SharePoint 2013 --> not okay - the Text Box is shrinked to the text Size and the design is defect
    How can i prevent this?
    Thanks in advance
    Sebastian
    I can provide Screenshots, bit at the moment my account is not verfied...

    Can you please share screen shot.
     Before try removing the field form View and  Add it again - check it
    Velu K

  • I can't enter any value in the Text field, after loading flash files

    Hi to all,
    In my Java application, I'm using a text field and a panel to load flash files. I'm using JDIC 0.9.1 to load the flash files in the panel. The flash files are created by Flash CS4.
    While running the application, I can't enter any value in the Text field, after minimize and maximize the application I can enter the values.
    This problem happens after change the jre version from 1.6 to 1.7.
    I'm getting the following exception while running the application.
    org.jdesktop.jdic.init.JdicInitException: java.io.IOException: The filename, directory name, or volume label syntax is incorrect
    at org.jdesktop.jdic.init.JdicManager.initBrowserNati ve(Unknown Source)
    at org.jdesktop.jdic.browser.WebBrowser.<clinit>(Unkn own Source)
    pls give me a solution.
    Thanks in advance...:)

    I can't enter any values in JTextField after loading the flash files., locking.

  • How to check for the sub folder in the document library Is already Exist using CSOM?

    Hi,
    My requirement is to create the  folder and sub folder in SharePoint document library. If already exist leave it or create the new folder and the subfolder in the Document library using client side object model
    I able to check for the parent folder.
    But cant able to check the subfolder in the document library.
    How to check for  the sub folder in the document library?
    Here is the code for the folder
    IsFolder alredy Exist.
    private
    string IsFolderExist(string InputFolderName)
    string retStatus = false.ToString();
    try
    ClientContext context =
    new ClientContext(Convert.ToString(ConfigurationManager.AppSettings["DocumentLibraryLink"]));
                context.Credentials =
    CredentialCache.DefaultCredentials;
    List list = context.Web.Lists.GetByTitle(Convert.ToString(ConfigurationManager.AppSettings["DocumentLibraryName"]));
    FieldCollection fields = list.Fields;
    CamlQuery camlQueryForItem =
    new CamlQuery();
                camlQueryForItem.ViewXml =
    string.Format(@"<View  Scope='RecursiveAll'>
    <Query>
                                            <Where>
    <Eq>
    <FieldRef Name='FileDirRef'/>
    <Value Type='Text'>{0}</Value>
                                                </Eq>
    </Where>
    </Query>
                                </View>",
    @"/sites/test/hcl/"
    + InputFolderName);
                Microsoft.SharePoint.Client.ListItemCollection listItems = list.GetItems(camlQueryForItem);
                context.Load(listItems);
                context.ExecuteQuery();
    if (listItems.Count > 0)
                    retStatus =
    true.ToString();
    else
                    retStatus =
    false.ToString();
    catch (Exception ex)
                retStatus =
    "X02";
    return retStatus;
    thanks
    Sundhar 

    Hi Sundhar,
    According to your description, you might want to check the existence of sub folder in a folder of a library using Client Object Model.
    Please take the code demo below for a try, it will check whether there is sub folder in a given folder:
    public static void createSubFolder(string siteUrl, string libName, string folderServerRelativeUrl)
    ClientContext clientContext = new ClientContext(siteUrl);
    List list = clientContext.Web.Lists.GetByTitle(libName);
    CamlQuery camlQuery = new CamlQuery();
    camlQuery.ViewXml =
    @"<View Scope='RecursiveAll'>
    <Query>
    <Where>
    <Eq>
    <FieldRef Name='FSObjType' />
    <Value Type='Integer'>1</Value>
    </Eq>
    </Where>
    </Query>
    </View>";
    //camlQuery.FolderServerRelativeUrl = "/Lib1/folder1";
    camlQuery.FolderServerRelativeUrl = folderServerRelativeUrl;
    ListItemCollection items = list.GetItems(camlQuery);
    clientContext.Load(items);
    clientContext.ExecuteQuery();
    Console.WriteLine(items.Count);
    if (0 == items.Count)
    //create sub folder here
    Best regards
    Patrick Liang
    TechNet Community Support

  • HT5622 how do I find out if the apple id is already existing?

    I have tried over and over again to reset my email to my Apple ID but it keeps telling me the ID already exists. I have tried to reset the password for that particular email but I don't receive the verification email as it says. I looked at the articles as to why I may not be receiving the email but none pertain to me. this is all for the purpose of changing the ID on my icloud account. I just need to know how many ID's I have set up in this email and how I can delete them.

    Hello jenny86753092008,
    Welcome to the Apple Support Communities! Your iTunes and iCloud passwords will always be the same unless you have multiple accounts with us. To check to see if you have multiple accounts, you can use this handy Apple ID tool:
    Apple - My Apple ID
    https://iforgot.apple.com/appleid
    You can also contact us for assistance to see if you have multiple Apple ID accounts:
    If you forgot your Apple ID password - Apple Support
    http://support.apple.com/en-us/HT201487
    Make sure that you’re entering the correct Apple ID. In most cases, your Apple ID is also the primary email address of your Apple ID account. If these steps didn't help you change your password, contact Apple Support.
    Cheers,
    Matt M.

  • RFCFILE7: Different Error messages on the same error: BP already exists...

    Hi,
    migrating Business Partners with the RKCFILE7 Direct input program gives 3 different error messages in case that the BP already exists:
    1.  BP & already exists in role BCA010
    2. BP with external number & already exists
    3. Data record to be created is alrady available in table BUT000
    The strange issue is, that migrating same BPs twice the error log gives for each BP one of these 3 error messages.
    However all 3 messages are valid for all BPs (they all exist).
    Any idea?
    Thanks
    Thomas

    does not matter anymore

Maybe you are looking for

  • On itunes my ipod app is not showing up.

    on itunes my ipod showig up but my app tab aint showing up.

  • Missing Adapter Engine in the XI Domain (in the RTWB view)

    Team, I am running at in a bizarre situation at a client site.  We have one SLD that is shared by 2 XI installations (a POC and a SandBox). In the POC (in run time workbench view), I can see all the XI component (integration engine, BPM engine, Adapt

  • Non-modal Popup possible- Factsheet in new window

    Hi, I have the requirement that I need to open the account factsheet in a new window. For that I have created a popup which works fine but I need this popup to be non-modal. Is there any way to do this? Or is there any other solution to open the fact

  • Facing issues in single step processing

    We are using single step processing, But facing issues while running GenData only. We get the desired output if we run GenData and GenPrint. And our Input file is XML Below is our AFGJOB.JDT and FSIUSER.INI(what we are using) AFGJOB /* This base (thi

  • Xorg/dvorak layout

    Hello, I am having problems using an dvorak keyboard layout with Xorg in Solaris 10. I added the following entries to /etc/X11/xorg.conf: <div class="pre"><pre> Section "InputDevice" Identifier "Keyboard0" Driver "keyboard" Option "XkbRules" "xorg" O