WriteUTF writing strange chars at the beginning?

I have the following class, which requires a Filename and a String:
class Log {
     public void appendLog(String Filename, String appendText) throws IOException {
          FileOutputStream outFile = new FileOutputStream(Filename, true);
          DataOutputStream outData = new DataOutputStream(outFile);
          outData.writeUTF(appendText);
          outData.close();
But the output always begins with this:
�AR

I have the following class, which requires a Filename
and a String:
class Log {
public void appendLog(String Filename, String
appendText) throws IOException {
FileOutputStream outFile = new
w FileOutputStream(Filename, true);
DataOutputStream outData = new
w DataOutputStream(outFile);
          outData.writeUTF(appendText);
          outData.close();
But the output always begins with this:
�AR Try this...
class Log {
        public void appendLog(String Filename, String  appendText) throws IOException {
               PrintWriter out= new PrintWriter(new BufferedWriter(new FileWriter(Filename,true)));
               out.write(appendText);
               out.close();
Hope it helped...
appu

Similar Messages

  • Exception:"Decrease the number of char between the beginning of the document and its root element"

    I'm now using a javabean in my jsp page to parse xml;when my xml file's size is
    about 10k,it just work fine;when my xml file's size became 50k,it throws the followng
    Exception:
    Failed to open xml document,Failed to retrieve Public id or system id from the
    document. Decrease the number of char between the beginning of the document and
    its root element. But when I run this javabean in JBuild ,it works fine no matter
    how big the xml file becomes;
    Why? the error message is in the attachment.

    The prologue must be included at the top of the document, followed by the root
              element.
              joden2000 wrote:
              > what does this exception mean:decrease the number of char between the beginning
              > of the document and its root element? When my xml file is about 10k,it works
              > just fine,when it becomes 50k ,the exception show.How can I deal with this?
              

  • Strange noise at the begining

    Hi everyone, I have a problem, I own a Satellite L35-SP4068 and when I start it, it make a kind of alarm and it don't begin windows vista, just if I enter the bios and start whit HD it begins, I don't know if you can help me with that, thank you. 

    Thank you for using the Toshiba Laptop Forums. Since there have been no posts to this thread in several days, it is being marked "read only" as part of our routine message board maintenance.
    If you still need assistance, please feel free to post a new message or contact the Toshiba Customer Support Center at 1-800-457-7777.
    Trina W
    Moderator

  • Junk char in the schema name

    I need to reset a password of a shcema which has Junk char in the begining...
    for eg., ABC.
    select * from dba_users where username ='ABC' ---- No rows selected.
    select * from dba_users where username like '%ABC' -- The user name is selected.
    Wondering how to reset or drop this User ??

    user 888442, Nck has shown you how to see the contents of the username column. To drop that user try placing the name in double quotes using exact case. you can then recreate the username as it was likely intended.
    HTH -- Mark D Powell --
    Corr user#
    Edited by: Mark D Powell on Jan 10, 2012 6:15 AM

  • The file adapter takes also the mark of the beginning of the file as a char

    Hi guys,
    I need to use the file adapter for sending data into XI.
    My first column of the CSV file contain ID of the objects of length 8 chars. But when the adapter takes also the beginning of the file, the length starts to be 9 chars.
    How is it possible to disallow to take this mark?
    I didn't find any parameter in the file adapter settings, which could solve this problem.
    Thanx for answer! (Points guaranteed )
    Peter

    Hi Peter,
             While configuring sender file adapter, you can do the following.
           1. While defining Parameters for Recordset Structures , you can make use of the recordsetstrucure.beginSeparator function which will take the first string in the file as a begin seperator.
      i guess this would help you.
    regards,
    Aravindh.

  • 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 to remove characters/lines from the beginning of an InputStream

    Hi,
    I have a program which receives several InputStreams. From each of these streams I have to remove 2 lines from the beginning. After the lines are removed, all the streams are combined to one with SequenceInputStream and read in one chunk. Is there an easy/simple way of doing this?
    One option I thought would be to read the char by char until 2 end of line chars have been detected and then read the rest of the data to a buffer. And the create a ByteArrayInputStream out of this buffer. Problem with this approach is, that the amount of data can be large, so putting all the data in to memory might cause problems.
    Another option is to use BufferredInputStream and use the readline() method twice to get rid of the lines that are not needed. After this I would write the data to some output stream, which is then converted back to input stream. Propably would work, but sound too much of work for a simple thing like this. There has to be better way.
    To make it simple, what I need is a method that looks like the following, or something similar
    *  Removes n number of lines from the beginning of a InputStream.
    *  @param is InputStream where the lines are removed
    *  @param numberOfLines int value to indicate how many lines whould be removed
    *  @return InputStream where lines have been removed.
    public InputStream removeLines(InputStream is, numberOfLines);Thanks.

    Here's the code, feel free to use it. Comments are also welcome.
    public InputStream removeLinesFromTheBeginning(InputStream is, int numberOfLines) throws IOException
              char c = 'c';
              int i = 0;
              for(int n = 0 ; n < numberOfLines ; n++)
                   do
                        c = (char)is.read();
                        System.out.print(c);
                        if(c == (char)-1)     // end of stream reached before any newline characters were found.
                             return null;
                        i++;
                   while(c != '\n');
                   System.out.println();
                   System.out.println("Characters removed:" + i);
                   System.out.println("n: " + n);
                   i = 0;
              return is;
         }Edited by: dave_spaghetti on Jun 16, 2009 5:42 AM
    Fixed a bug.

  • Make an alert box at the beginning of every month

    I'm writing a budgeting tool and at midnight at the beginning of every month I want to pop up an alert saying it is the start of a new month and enable a button in jsp.
    I have tried a couple ways to do this. First I wanted to keep creating a calendar and check if the date was 1. But then this would be much more work than is needed.
    Next I tried to use the TimerTask class and set a boolean to true at the first of every month, but then I couldn't figure out how to make the javascript run when the run method of that thread executes. I tried using a while loop in the jsp page itself to check the boolean but this just caused the page to hang.
    A third idea I was trying is to have an invisble form with a hidden field using this boolean. I was trying to figure out a way to use onChange to trigger the javascript, but this would only work for some sort of visible input.
    Anyone have any exprience on scheduling a task like this at the beginning of every month or about how to force a page to reload at a specific time? Thanks.

    You could even put that in a frame with a form to navigate a seperate frame:
    //frameset
    <html>
    <frameset frameborder="0" framespacing="0" rows="26px,*">
    <frame scrolling="no" frameborder="0" marginheight="0"
        marginwidth="0" name="frameA" noresize src="testingB.jsp" />
    <frame scrolling="no" frameborder="0" marginheight="0"
        marginwidth="0" name="frameB" noresize src="http://www.google.com" />
    </frameset>
    </html>
    //then your time-important page (called testingB above)
    <html>
    <body>
        <script type="text/javascript">
            function navigate() {
              var navigateTo = document.forms[0].address.value;
              if (navigateTo.toLowerCase().indexOf("http://" == -1)) {
                  navigateTo = "http://"+navigateTo;
              parent.frameB.location.href = navigateTo;
              return false;
            function doAlert() {
                alert("Time to do Something");
                window.location.reload(); //so it will happen again next month.
    <%
        //When first created, the calendar points to now.
        Calendar cal = Calendar.getInstance();
        long curTime = cal.getTimeInMillis();
        //then, lets set it to the 1st day of the month, at 00:00:01.00 (1 second after midnight
        cal.set(Calendar.DAY_OF_MONTH, 1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 1);
        cal.set(Calendar.MILLISECOND, 0);
        //finally, add a month to get the first second of next month
        cal.add(Calendar.Month, 1);
        long triggerTime = cal.getTimeInMillis();
    %>
            //set the doAlert to occur after the # of milliseconds between now and
    next month.
            setTimeout("doAlert()", <%= (triggerTime - curTime) %>);
        </script>
        //form will read address you type in input, and navigate the other frame there.
        <form onSubmit="navigate();" name="nav">
          <input type="text" name="address" size="100" style="margin:3px" />
          <input type="submit" name="Go" value="Go" style="margin:3px" />
        </form>
    </body>
    </html>

  • Components are not visible in the beginning..

    Hai ..
    The contents(TextFields Labels and Buttons) of my application are displayed only after i resize the frame manually.. Why is it so.. Is there any way to make them visible as soon as i run the application..
    This happens only for the first time(ie immediately after running the application..).. I guess its because of the Focus not being given to the Frame in the beginning(I may be wrong.. Correct me if i am wrong).. Any one with any solution??
    Thanks in advance!!

    /* This program is meant for opening the internet explorer on typing the search text in the TextField and pressing enter*/
    public Search()
    f=new Frame();
    maxwidth=Toolkit.getDefaultToolkit().getScreenSize().width;
    maxheight=Toolkit.getDefaultToolkit().getScreenSize().height;
    f.setBounds(maxwidth-200,0,200,maxheight);
    f.setVisible(true);
    f.setLayout(null);
    f.setBackground(Color.BLACK);
    f.setForeground(Color.RED);
    st=new JTextField();
    sl=new JLabel("Search");
    sl.setBounds(25,525,150,25);
    st.setBounds(25,565,150,25);
    sl.setForeground(Color.RED);
    f.add(sl);f.add(st);
    /* On pressing Enter i try to convert the contents in the textbox in a search string to be used in google*/
    st.addKeyListener(new KeyAdapter()
    public void keyPressed(KeyEvent ke)
    if(ke.getKeyCode()==KeyEvent.VK_ENTER)
    searchstring=st.getText();
    char ss[]=searchstring.toCharArray();
    for(int i=0;i<ss.length;i++)
    if(ss==' ')
    ss[i]='+';
    searchstring=new String(ss);
    try
    p=Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\iexplore.exe www.google.co.in/search?hl=en&q="++searchstring++"&meta=");
    catch(Exception e1)
    System.out.println("Internet Explorer not found in C drive");
    try
    p=Runtime.getRuntime().exec("E:\\Program Files\\Internet Explorer\\iexplore.exe www.google.co.in/search?hl=en&q=+"+searchstring++"&meta=");
    catch(Exception e2)
    System.out.println("Internet Explorer not found in E drive");
    f.addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent we)
    f.setVisible(false);
    /* This imgpanel is used to display an image in the JPanel*/
    imgpanel=new JPanel();
    imgpanel.setLayout(new GridLayout(1,1));
    f.add(imgpanel);
    imgpanel.setBounds(25,50,150,150);
    img=Toolkit.getDefaultToolkit().getImage("sample.jpg");
    img=img.getScaledInstance(150,150,Image.SCALE_SMOOTH);
    imgicon=new ImageIcon(img);
    imglabel=new JLabel(imgicon);
    imglabel.setVisible(false);
    imgpanel.add(imglabel);
    On executin the code i get the frame visible .. The JPanel is also visible but the image is not present.. Its visible once I resize the frame.. Also the TextField(for getting the search text)and the associated JLabels are sometimes not visible.. They are visible only if i bring some other window in front of it or if i resize the Frame..
    Thanks!!
    Edited by: s.baalajee on Jan 7, 2009 9:44 AM
    Edited by: s.baalajee on Jan 7, 2009 9:45 AM

  • ATV3 plays wrong song and has gap at the beginning

    Hi there,
    just got my ATV3 exchanged, because the old new one has got this media-library-connection-error, however with the new one I am experiencing a strange behaviour via WLAN and via Ethernet.
    Whenever I stream music and skip songs manually playback will start immediately from the beginning of each song.
    Playing playlists or entire albums causes a freeze at the beginning of a new song and playback starts between 3 or 6 seconds later, from this length of gap on in the song, so not starting at the beginning. Often it plays a different track than the one displayed (most of the time the next in sequence).
    Anybody else experiencing this?
    Thanks for your help,
    Andreas

    Solved it by turning homesharing off an on again!

  • Is there a property to set the position of a table-scrollbar to the begining?

    Hello,
    i have a VI which displays a table and the table gets data from time to time.
    Are there any properties that i can use to set the scrollbar at the right side to the beginning of the table?
    The scrollbar stays always at the last position.
    Thx for your help.

    The property is "Index values"
    Message Edité par chilly charly le 11-08-2007 04:03 PM
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Example_BD.png ‏1 KB

  • Selecting words in the beginning of a LINE (not a paragraph)

    Hi
    I'm trying to avoid certain combinations to fall at the beginning of any line in a body text.
    How do I select a particular character only if it occurs in the beginning of a line (but in the middle of a paragraph.
    For instance I want to select the char "a" only if it occurs at the left margin of a column
    I only find the location marc "beginning of a paragraph" (^), or beginning of a word,  but not the beginning of a line.
    It could be as grep, or as a script.
    Anybody?
    Thank you
    /javier

    It would need a script. GREP is not aware of the individual lines in a paragraph.
    The good news is, InDesign's scripting language is fully aware of lines. There are, on first sight, two possible ways of locating all a's at the start of a line. Either search for all a's (doesn't need a GREP, but you must remember to set caseSensitive in the FindChangePreferences) and loop over them, checking for the ones that are at the start of a line, or check all lines one by one, checking for the ones that start with an 'a'.
    Both options seem equally slow I guess what to use depends on your text, and what you'd want to do when one is found. On that note: you must process them from last found to first, because if you change something, it may have an effect on all text that follows.

  • Sending a program back to the beginning..

    I dont think the topic explains it right, but I need to be able to go back to the beginning of the block again if it loops. I'll just post the code as its probably easier to see what I want to do that way... :)
    public class ABCInput
         public static void main(String []args) throws Exception
              char letterInput;
              System.out.println("Type A, B, C, or Q.");
              letterInput = (char)System.in.read();
              System.in.read();
              System.in.read();
              while (letterInput != 'A' || letterInput != 'B' || letterInput != 'C' || letterInput != 'Q')
                   System.out.println("Incorrect, try again.");
                   letterInput = (char)System.in.read();
                   System.in.read();
                   System.in.read();
              while (letterInput == 'A' || letterInput == 'B' || letterInput == 'C')
                   System.out.println("Good Job.");
                   System.out.println("Add another character");
                   letterInput = (char)System.in.read();
                   System.in.read();
                   System.in.read();               
              if (letterInput == 'Q')
                   System.out.println("Exiting Application!");
                   System.exit(0);     
    }

    Instead of putting little loops around each case, put a large one around everythingchar letterInput;
    System.out.println("Type A, B, C, or Q.");          
    letterInput = (char)System.in.read();
    while (letterInput!='Q') {
       If (letterInput=='A' || letterInput == 'B' || letterInput == 'C') {
           //blah
      } else {
        System.out.println("Incorrect, try again.");
      letterInput = (char)System.in.read();
    System.exit(0);

  • How would I erase the beginning of a file?

    I want to be able to erase the beginning of a file, while writing to the end...WITHOUT reading the whole file and writing it again because that would be a waste of resourses. Obviously I know that option is available.
    My situation is that I am adding lines to a log file, and I want to remove any entries that are X hours old. Logging a lot of information would mean that every few seconds, an entry is older than X hours and needs to be removed. It doesnt have a set number of lines so I can't just recycle the file by doing something like: if at line number Y, start at line 1 and remember the current line number.
    Adding to the top of the file, pushing the others lines down, and making cuts at the end would also work, but the same situation arises, how do I add to the beginning of the file, without having to copy the entire file to add the entry to the top.
    The reason I don't want to read the whole file is because having to read the whole file and write the whole file when an entry is made is time consuming and wastes CPU and memory, especially when the logs are coming in several lines a second.

    I would think it could easily be done. say you want to erase the first 10 bytes, why cant you just say move the start of the file up 10 bytes. Somewhere in the filesystem the start of the file is stored. I found underlying file copying that claims this in FileChannel's transferTo and transferFrom:
    This method is potentially much more efficient than a simple loop that reads from this channel and writes to the target channel. Many operating systems can transfer bytes directly from the filesystem cache to the target channel without actually copying them.
    If I can't just chop, I'll have to copy quickly at scheduled intervals.
    This is code I ran to test the above quote:
        public static void main(String[] args) throws Exception{
            args = new String[2];
            BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("Enter File Name:");
            args[0] = input.readLine();
            System.out.println("Enter test (0-2):");
            args[1] = input.readLine();
            long time = System.currentTimeMillis();
            int version = Integer.parseInt(args[1]);
            switch (version) {
                case 0:
                    BufferedReader in = new BufferedReader(new FileReader(args[0]));
                    PrintWriter out = new PrintWriter(new FileWriter("tempfile.txt"));
                    in.readLine();//skip line.
                    for (String line = in.readLine();line != null;line = in.readLine()) {
                        out.println(line);
                    in.close();
                    out.close();
                    break;
                case 1:
                    RandomAccessFile raf = new RandomAccessFile(args[0],"rw");
                    String line = raf.readLine();
                    long offset = raf.getFilePointer();
                    byte[] b = new byte[1024];
                    int bytes = 1024;
                    long index = 0;
                    System.out.println("index = " + raf.getFilePointer());
                    System.out.println("index = " + line.length());
                    while(bytes == 1024) {
                        bytes = raf.read(b);
                        index = raf.getFilePointer();
                        raf.seek(index - bytes - offset);
                        raf.write(b,0,bytes);
                        raf.seek(index);
                    raf.setLength(raf.length()-offset);
                    raf.close();
                    break;
                case 2:
                    RandomAccessFile raf2 = new RandomAccessFile(args[0],"rw");
                    String line2 = raf2.readLine();
                    long offset2 = raf2.getFilePointer();
                    FileChannel f = raf2.getChannel();
                    FileChannel g = f.position(0);
                    g.transferTo(offset2,raf2.length() - offset2,f);
                    raf2.setLength(raf2.length()-offset2);
                    raf2.close();
                    break;
            System.out.println(System.currentTimeMillis() - time);
        }and had these results
    166MB Log File
    Linux Mandrake 900Mhz
    Case 0 = 32914 ms
    Case 1 (1k byte[]) = 15043 ms
    Case 1 (16k byte[]) = 6988 ms
    Case 1 (1MB byte[] = 6113 ms
    Case 2 = 6188 ms
    :-/ guess this proves that the FileChannel can't chop

Maybe you are looking for

  • When i open the gmail account i found the ssl_error_rx_record_too_long what i do.

    Dear Sir when i open the gmail i got this message. Plz tell me what i do. Secure Connection Failed An error occurred during a connection to accounts.google.com. SSL received a record that exceeded the maximum permissible length. (Error code: ssl_erro

  • Transfer all Data Production to Quality

    Hi all, I want to transfer all Production data to Quality server . This procedure i thing done with client export or import position . And done with T-Code SCC8 FOR EXPORT AND SCC7 FOR IMPORT.  So please let me know am i right or not ? or any other p

  • Trouble syncing email account

    My mac mail works fine with my iphone. My other email is through my university and I cannot get it to sync...it says something about a POP or IMAP account? Does anyone know how to set it up? I do not even know what the POP or IMAP is..the mail accoun

  • ScriptLink tag not working for application page sharepoint 2010

    <ScriptLink> tag not working for application page sharepoint 2010 for including javascript in application page, it appends either 1033 or _layout to path specified for javascript.But javascripts are located in custom document library on site and not

  • How to determine runtime of SNP optimizer

    Hi Experts, I am new to SNP optimizer, i would like to know the factors that determine the runtime of SNP optimizer, for example if i have 100 product-loc combination, what should be my runtime? Thanks in Advance Raja kiran R