Weird characters appear after write to a file

Here is my story:
I open a file using RandomAccessFile to replace some characters inside it. Let's say I have in the file string 4000, I replace it by string 400. It works fine.
Now if I replace this number by string 40000, when I check the text file, some weird characters like ^M appear everywhere at the end of lines.
What's the reason and how to solve it? I believe there is some invisible characters at the end of string 4000 that causes the problem.
Note that I use function writeBytes to write strings into the file.

public static void changeFileRAF(String sFile, String paramName, String paramValue) {
try {
RandomAccessFile rf = new RandomAccessFile(sFile, "rws");
String currentLine;
long pos;
while (true) {
pos = rf.getFilePointer();
currentLine = rf.readLine();
if (currentLine == null)
break;
if (currentLine.trim().startsWith(paramName)) {
rf.seek(pos);
char[] replaceLine = currentLine.toCharArray();
char[] value = paramValue.toCharArray();
int i = 0;
//pass all white space characters
while (i < replaceLine.length && Character.isWhitespace(replaceLine)) {
i++;
//pass all characters representing tag name
while (i < replaceLine.length && !Character.isWhitespace(replaceLine[i])) {
i++;
//again, pass all white space characters
while (i < replaceLine.length && Character.isWhitespace(replaceLine[i])) {
i++;
if (i == replaceLine.length) {//no value, do nothing                                                           
return;
int oldValueLength = replaceLine.length - i;
String newLine = System.getProperty("line.separator");
if (oldValueLength >= value.length) {
System.out.println("different: " + (oldValueLength - value.length));
for (int j = 0; j < value.length; j++)
replaceLine[j + i] = value[j];
for (int j = value.length; j < oldValueLength; j++)
replaceLine[j + i] = ' ';
rf.writeBytes(String.copyValueOf(replaceLine));
else {
System.out.println("old value length: " + oldValueLength);
System.out.println("new value length: " + value.length);
char[] compensation = new char[value.length - oldValueLength];
for (int j = 0; j < oldValueLength; j++)
replaceLine[j + i] = value[j];
for (int j = oldValueLength; j < value.length; j++)
compensation[j - oldValueLength] = value[j];
System.out.println("it is " + String.copyValueOf(replaceLine) + String.copyValueOf(compensation));
rf.writeBytes(String.copyValueOf(replaceLine) + String.copyValueOf(compensation));
break;
rf.close();
} catch (IOException e) {
System.out.println(e.getMessage());
I hope it's not too long.

Similar Messages

  • Weird characters appear in title bar when windows are maximised

    I am using awesome WM and when windows are maximised weird characters appear.  It appears normal when unmaximised.
    Maximised window:
    Unmaximised window:

    Well I finally figured out (accidentally )  that these indicate the state of window i.e floating, maximised horizontally, maximised vertically.

  • Characters appearing after Import when no character is listed on the Original Document

    Good Afternoon ~
    I'm hoping someone can assist with my issue. In the context
    of the document there is a (c1) appearing after a sentence even
    though there is no characters or anything on the original document.
    HELP

    Sorry but you are still not providing a clear picture.
    After what file has been imported into what? Importing is
    something the author does but you are are talking about an end user
    and how would they know what was in the original file?
    Please try again.

  • Weird characters appear in text when I send email to a PC

    All
    When I send an email to a recipient using a PC vs an Apple product.
    I have provided a sample of the weird characters that are NOT typed in but show up in the text.  I see it AFTER it is sent out to the recipient.
    It does NOT happen all the time.
    Thanks for any help.
    Hey JoeŠ
    Haven¹t we seen this company before while responding to these DAS projects? 
    They are  they Œinterested vendors¹ for the DOE job.

    Start copying yourself on outgoing mail. If you don't see the extra characters in your copy of the sent message, then the problem is at the recipient's end.

  • Odd Characters Appearing after Adobe Flash Update

    After updating to the latest version of Adobe Flash, there are weird characters showing on the tabs at the top of the screen. I'm a little concerned what this might indicate.

    hello ka5biw, this is a displaying flaw caused the mcafee site advisor extension - please try to disable or remove that in case you have it present until there is an update by mcafee that can fix the problem.
    http://service.mcafee.com/faqdocument.aspx?id=TS100162
    https://community.mcafee.com/thread/76071

  • Asian characters appear after last update

    I just installed the latest Adobe Reader update and after completing steps 1-3, I get a message in center of screen in Asian characters and none of my PDF files will open now.

    Thank you!  Yes, that was my problem.  I got it resolved and went to my
    Preferences and unchecked the box for "Allow plug-ins."  All is well now.
    Thank you so much for the quick response.
    --P
    On Fri, Jul 11, 2014 at 4:23 PM, MobileDevCK <[email protected]>

  • Weird characters displayed on page instead of file download/preview

    Hi everyone,
    I have a download file procedure as per the instructions on the download.oracle.com page
    The download of the files worked just fine (or better say they were previewed in a new page) but recently a new schema has been added to the workspace so we can start the testings from the scratch.
    I modified the schema name where needed, but not the download page acts kinda weird, as instead of the file preview, I get a long page full of:
    �����JFIF�,,����&�Exif��MM�*������������������b�������j(�������1�������r2���������i�������������-����'�-����'Adobe Photoshop CS3 Windows�2008:07:28 16:41:20���������������������������]��������������������������&(�������������.������%��������H������H��������JFIF���H�H�����Adobe_CM�
    The issue is that if I switch back to the old schema, the result is the same. So, anyone has any idea of what can cause this?
    Thank you
    Regards
    Andrea

    Hi John,
    >
    <Location /pls/nxdev>
    Order deny,allow
    PlsqlDocumentPath docs
    AllowOverride None
    PlsqlDocumentProcedure wwv_flow_file_manager.process_download
    PlsqlDatabaseConnectString hostname:1521:... ServiceNameFormat
    PlsqlNLSLanguage NORWEGIAN_NORWAY.AL32UTF8
    PlsqlAuthenticationMode Basic
    SetHandler pls_handler
    PlsqlDocumentTablename wwv_flow_file_objects$
    PlsqlDatabaseUsername APEX_PUBLIC_USER
    PlsqlDefaultPage apex
    PlsqlDatabasePassword pass
    Allow from all
    </Location>>
    >
    CREATE OR REPLACE procedure schema.dl_file (p_fileid in number)
    as
    l_mime varchar2(255);
    l_length number;
    l_filename varchar2(2000);
    lob_loc BLOB;
    begin
    select col1,col2,col3,col4 into l_filename, l_length, l_mime, lob_loc from km_docs where kmd_id = p_fileid;
    -- Set up HTTP header
    -- Use an NVL around the mime type and if it is a null, set it to
    -- application/octect - which may launch a download window from windows
    owa_util.mime_header(nvl(l_mime,'application/octet'), FALSE );
    -- Set the size so the browser knows how much to download
    htp.p('Content-length: ' || l_length);
    -- The filename will be used by the browser if the users does a "Save as"
    htp.p('Content-Disposition: filename="' || l_filename || '"');
    -- Close the headers
    owa_util.http_header_close;
    -- Download the BLOB
    wpg_docload.download_file( Lob_loc );
    end;
    >
    Thanks!
    PS: Some updates...I tried it in IE as well (I use FF when working with applications) and funny enough the photos and documents get displayed/the download box shows up.
    But, all the files have the name f. f.pdf, f.jpeg etc
    I tried calling the dl_image procedure in the url (currently I call a new page where I pass the file id to an application id and then I call the above procedure in a pl/sql block):
    http://www.host/pls/dad/schema.dl_file?p_fileid=1
    And the name seems ok. I don't think it's a good idea to put the procedure name in the link, is it?
    Edited by: AndreaC on Nov 18, 2008 3:30 PM

  • Weird characters displayed after Windows update

    A user encountered this issue after a Windows update.
    https://twitter.com/summerscope/status/414887724131168256/photo/1
    Did anyone encounter this too, and what did you do?
    Thanks in advance.
    serene
    Community Advocate Program Manager
    English Community   Deutsche Community   Comunidad en Español   Русскоязычное Сообщество

    Hi John,
    >
    <Location /pls/nxdev>
    Order deny,allow
    PlsqlDocumentPath docs
    AllowOverride None
    PlsqlDocumentProcedure wwv_flow_file_manager.process_download
    PlsqlDatabaseConnectString hostname:1521:... ServiceNameFormat
    PlsqlNLSLanguage NORWEGIAN_NORWAY.AL32UTF8
    PlsqlAuthenticationMode Basic
    SetHandler pls_handler
    PlsqlDocumentTablename wwv_flow_file_objects$
    PlsqlDatabaseUsername APEX_PUBLIC_USER
    PlsqlDefaultPage apex
    PlsqlDatabasePassword pass
    Allow from all
    </Location>>
    >
    CREATE OR REPLACE procedure schema.dl_file (p_fileid in number)
    as
    l_mime varchar2(255);
    l_length number;
    l_filename varchar2(2000);
    lob_loc BLOB;
    begin
    select col1,col2,col3,col4 into l_filename, l_length, l_mime, lob_loc from km_docs where kmd_id = p_fileid;
    -- Set up HTTP header
    -- Use an NVL around the mime type and if it is a null, set it to
    -- application/octect - which may launch a download window from windows
    owa_util.mime_header(nvl(l_mime,'application/octet'), FALSE );
    -- Set the size so the browser knows how much to download
    htp.p('Content-length: ' || l_length);
    -- The filename will be used by the browser if the users does a "Save as"
    htp.p('Content-Disposition: filename="' || l_filename || '"');
    -- Close the headers
    owa_util.http_header_close;
    -- Download the BLOB
    wpg_docload.download_file( Lob_loc );
    end;
    >
    Thanks!
    PS: Some updates...I tried it in IE as well (I use FF when working with applications) and funny enough the photos and documents get displayed/the download box shows up.
    But, all the files have the name f. f.pdf, f.jpeg etc
    I tried calling the dl_image procedure in the url (currently I call a new page where I pass the file id to an application id and then I call the above procedure in a pl/sql block):
    http://www.host/pls/dad/schema.dl_file?p_fileid=1
    And the name seems ok. I don't think it's a good idea to put the procedure name in the link, is it?
    Edited by: AndreaC on Nov 18, 2008 3:30 PM

  • Weird characters in known_hosts file

    We have a Solaris 9 Client system that does ssh to other Solaris servers.
    StrictHostKeyChecking is set to "No" in /etc/ssh_known_hosts.
    Even when the public host key of the servers do not change we see that there are multiple entries in $HOME/.ssh/known_hosts file of the client.
    How can this happen?
    And some times, we have weird characters in place of the ip address and encryption algorithm, while the actual key is properly written into known_hosts file.
    How these weird characters are put into the known_hosts file?
    If anyone can provide the answers, it will be of great help.
    Thanks in advance.

    not sure i follow fully, can you check for this setting:
    HashKnownHosts yes
    in ssh_config. this will hash keys in known_hosts to make it unreadable...

  • Computer is slow to respond when mouse is clicked and typed letters appear after a delay of several seconds

    When I type or start to type the characters appear after a delay. Scrolling up and down and clicking on some tabs or links is very slow.

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    It is possible that there is a problem with the files sessionstore.js and sessionstore.bak in the Firefox Profile Folder.
    Delete the sessionstore.js [2] file and possible sessionstore-##.js [3] files with a number and sessionstore.bak in the Firefox Profile Folder.
    * Help > Troubleshooting Information > Profile Directory: Open Containing Folder
    * http://kb.mozillazine.org/Profile_folder_-_Firefox
    Deleting sessionstore.js will cause App Tabs and Tab Groups and open and closed (undo) tabs to get lost, so you will have to create them again (make a note or bookmark them).
    See also:
    * [1] http://kb.mozillazine.org/Session_Restore
    * [2] http://kb.mozillazine.org/sessionstore.js
    * [3] http://kb.mozillazine.org/Multiple_profile_files_created

  • [Solved/Workaround found] XFCE/Firefox/Thunderbird: Weird characters

    Hi,
    since a few days, there have been weird characters appearing in texts, especially in Firefox, but also in Thunderbird or in the XFCE desktop environment. There you can find a screenshot to see what I mean: http://i.snag.gy/y2Xom.jpg
    I found this topic: https://bbs.archlinux.org/viewtopic.php?id=151095
    and installed harfbuzz-git, with no change, and also cairo-git, from AUR, but this does not help either.
    Is this kind of a bug in XFCE, or in some of the new Gnome 3.6 libraries?
    Thanks!
    jellysheep
    [EDIT] This is with nvidia drivers, enabling or disabling compositing does not change anything.
    Last edited by jellysheep (2012-11-13 17:16:09)

    https://bbs.archlinux.org/viewtopic.php?id=152837

  • Japanese lyrics shown on iPhone become weird characters after some number of plays

    I put in lyrics for my Japanese songs both the kanji/kana and romaji. There have been no problems before this. But somehow I suppose after the newest iTunes released I added some new songs and there were two of them that I added lyrics into them. At first their lyrics were shown properly on my iPhone screen. But after some time the kanji/kana became some weird characters. I checked the lyrics in iTunes and there seemed to be no problems at all with my lyrics. I needed to delete the song from both my phone and my iTunes library and re-add then re-synced it again. (just deleting the song from the phone and then re-synced it didn't help.) Then again, today the lyrics became weird again. I don't really understand. It would become very annoying if this keeps going on. I would appreciate any advice and help. Thank you very much.

    I just tried this with my iPhone 4 and it also didn't work.  This is how it failed:
      - Select "shared".
    - The "pie" start to grow, got to about 1/3, then crashed without
        bringing in the shared content.
    - After that, the library appeared in list, but I couldn't select
        it at all anymore.
    Then I tried it with my iPad.  The pie got to the same point, sat
    there for a long time, then completed and worked fine.
    I did a hard reset of the phone and tried again, this time it
    behaved like the iPad and worked fine.
    Not sure whether it was the hard reset or whether sharing with
    another device "woke something up", but in any event it works
    now and I can't get it to break again.
    Note, I only use sharing for movies, since I have Music Match
    (which works *great* for me, even on 3G).
    Specs:
      Sharing: 2.7 GHz iMac i5, OS 10.6.8
      Clients: iPhone 4
                  4th gen iPad
    Everything (including iTunes) patched to the latest.

  • Hi this message appears after 2 hours downloading Mavericks : an error occurred while extracting files from the package "mzps4135638417199433253.pkg"

    Hi this message appears after 2 hours downloading Mavericks in App Store :
    an error occurred while extracting files from the package "mzps4135638417199433253.pkg"
    Same with "CMD + R"
    Help...

    It sounds to me like your Internal Hard Drive is failing.
    I recommend you buy a new one, that is a good candidate for replacing the old one, but install it in an External enclosure and Install a fresh Mac OS X on it from the DVD. You can boot your Mac from any attached drive.
    The new System can be used to get some work done, check your emails, and takes the pressure off resolving this immediately. You can also attempt to salvage files off the old drive if needed.
    Once things seem to be working, then move the new drive inside the computer. Failures at this point may be due to bad cable, which has been a problem in some of these MacBooks.
    Use security erase, write Zeroes, one pass, to re-write every block on the old drive. Any block discovered to be bad will be replaced with spares the drive holds in reserve for this purpose. If more than 10 blocks are pared on one pass, "Initialization Failed!" will be the result. Although you can try the erase again, there is some question whether you want to trust this drive with your precious data.

  • MPEG-2 File !DO..." followed by a bunch of weird characters.

    After compressor creates MPEG-2 files, with the extension .m2v have their "Kind" listed in the Finder as "MPEG-2 File <!DO..." followed by a bunch of weird characters.>
    Anyone know what is going on? There was a post back in January with the same issue, but no answer.
    Thanks

    You can have multiple iPods and iPhones syncing to the same iTunes library, and you can separately control what goes on each using the Sync Selected Playlists.

  • After upgrading to the latest version of itune, I get this message when trying to open itunes: "The I'tunes Library File is locked, on a locked disk, or you do not have permission to write for this file.

    After importing the latest version of itune, I now get this message:  "The I-tunes library file is locked, on a locked disk , or you do not have permission to write for this file.  How do I resolve this?

    check if you have read & write permissions for your music folder. in the finder, right-click on it and get info. unlock the little padlock (you may have to enter your admin password) and change the permission settings if necessary. next, click on the little gear-shaped icon and apply to enclosed items like so
    the important part is to apply to enclosed items !
    also, even if it seems unrelated, try the steps in this support article: iTunes: Missing folder or incorrect permissions may prevent authorization

Maybe you are looking for

  • Rendering Error when using more than one DataSheetView on a Enterprise Wiki-Page

    Hi Experts, how to reproduce: Add two Custom Lists with some Fields (Add Lookup-Columns to both Lists). Add a DataSheetView to each List and mark it as Default-View Create a Enterprise Wiki-Page Add a WebPart (Custom-List-1) You will see the Content

  • Ipod will start-up then shut off

    Hi - need your help before vacation on a long holiday weekend. As of yesterday, my video ipod was working great. Now, when I turn it on or plug it in, it continually tries to turn on by showing the Apple logo then shuts off and keeps doing this. It w

  • Visible of sprite script trouble

    hi list I need to have a few sprites invisible on opening of my program and have them appear when rolled over. I am using the following script in the script channel above the play head: on mouseLeave me the visible of sprite 34 = 0 end mouseLeave me

  • Network sizing for SAP printing

    Dear all, We are in the midst of sizing network bandwidth requirement for SAP implementation which involves some remote locations. Actually Iu2019ve gone through the documentation (Front-End Network Requirements for SAP Business Solutions), and found

  • HT4623 why cant we be able to save contacts to our phone like every other phone?

    When i get a new iphone i loose some cantacts, because you cant save them to the sim card from the iphone, and iknow you can do it throught the computer save them there, but what happens if the computer breaks? I think this should be a feature added