How to write thread safe to a file..please help!!

Hi,
need a sample writing thread safe to a file.
thanks

`Or create a class that has a private BufferedWriter to the file, opened in append mode, and in your "print" or "write" method, synchronize on the BufferedWriter..ie...
given a BufferedWriter bw that's already open to append mode.
public void write(String s)
synchronized(bw)
    bw.write(s);
    bw.flush(0;
}

Similar Messages

  • Anyone knows how to write WBMP image ??? please help !

    hi all,
    anyone knows how to write WBMP image, please show me !
    thanks.

    http://www.google.com/search?q=wbmp
    Please do not create additional posts, just refresh ("bump") the original.

  • How to write data to an XML file present under application server

    frnds: can ne one tell me, how to write data in to a file, which is present under a application server
    Ex: i want to write a string data in to a file test.txt which is present under "http://localhost:8080/<some_webapp>/test.txt"
    Note:i have deploted a service<some_webapp> under Tomcat/webapps dir

    Very simple. A servlet can writes to that file if it has the good rights.
    In the servlet get (or post) method, use a code like this:
    import java.io.*;
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
    try {
    String filePath = this.getServletContext().getRealPath("/text.txt");//See http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/ServletContext.html#getRealPath(java.lang.String)
             PrintWriter writer = new PrintWriter (filePath);
            //or BufferedWriter out = new BufferedWriter(new FileWriter(filePath));
            writer .println("aString");
           writer.flush();
            writer .close();
        } catch (Exception e) {
           e.printStackTrace();
    }Hope That Helps

  • How to write new line to a File?

    How to write new line to a file?
    I have a string to be written to a file. the string contains "\n" in it. But why it is not showing the new line in the file.
    I have tryed FileWriter class and FileOutputStream class, but none of them works?
    any suggestion please...

    Probably using PrintStream::println() is a portable way.
    import java.io.FileOutputStream;
    import java.io.PrintStream;
    public class NewLine {
        public static void main(String[] args) {
         try {
             PrintStream ps = new PrintStream(new FileOutputStream("foo.txt"));
             ps.write("string".getBytes());
             ps.println();
             ps.close();
         } catch (java.io.IOException e) {
             e.printStackTrace();
    }Regards,

  • How to write new line on resource file.

    Hello Everyone,
    Can you please help me add new row on resource file, here is the code i have used to read my resource file.
    I have no idea on how to add new line... Please help 
    private void btnBrowse1_Click(object sender, EventArgs e)
    BrowseFile();
    //versionIncrement();
    if (txtInputfile.Text.Length > 0)
    PathSelection = txtInputfile.Text;
    oDataSet = new DataSet();
    //now am reading the files fro the path that is selected
    XmlReadMode omode = oDataSet.ReadXml(PathSelection);
    for (int i = 0; i < oDataSet.Tables[2].Rows.Count; i++)
    string comment = oDataSet.Tables["data"].Rows[i][2].ToString();
    //the elements array contain all the columns filled
    string[] elements = comment.Split('-'); //when it reaches the comma, it will jump to the next line
    string font = elements[0]; //Font
    string datestamp = elements[1]; //DateStamp
    string commentVal = elements[2]; //Comment
    string[] row = new string[] { oDataSet.Tables["data"].Rows[i][0].ToString(), oDataSet.Tables["data"].Rows[i][1].ToString(), font, datestamp = DateTime.Now.ToString(), commentVal };
    Gridview_Input.Rows.Add(row);

    Hello
    Sitholimela,
    >> Can you please help me add new row on resource file, here is the code i have used to read my resource file.
    From your description, it seems that your resource file is a XML format file, if so, you could also have a try to use
    LINQ To XML which is easy to operate the XML file to add new row to your resource file, and here is an example to show how to add a new element/row to the specific tree:
    Linq to XML Add element to specific sub tree
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • I'd like to know how to change my profile picture that appears on mail threads on my mac.  please help.

    I'd like to know how to change my profile picture that appears on mail threads on my mac.  please help.

    There may be other methods, but below is how I change my email photo.
    Here is how to change your Mac Mail email photo in Mountain Lion:
    Open the App called "Contacts". Type your name in the search field. Your contact info and photo should appear. Click on your photo. You now have some photo options. I use the "Recents" tab, and simply drag photo files from Finder into that window in Contacts. Drag and drop.
    If you have trouble finding yourself in "Contacts" you can also get there by doing this:
    Open one of your sent messages. Double click your photo in that message. This opens another window with your photo in it. Double-click that photo. This should open your contact information in the Contacts App.
    Hope this helps.
    -Craig

  • HOW TO - Create new from clipboard and process multiple files - please help

    Need help - have new version of photoshop on trial only ATM...
    Want to know - HOW TO:
    1. Create new from clipbaord
    2. Process multiple files
    Please help.

    For clipboard copy, I start with File > New and the size will be set to what's in the clipboard. Then once the new file is opened, Edit > Paste will place the clipboard contents as a layer in the new document.
    You must remember to use the command Layer > Flatten Image of you want to save as jpeg or any other file format that doesn't support layers.
    For processing multiple files,
    File > Automate > Batch or
    File > Scripts > Image Processor...
    Check the User guide or google information for those commands if you have specific needs.
    Gene

  • How to view corrupted word files, please help?

    Can't view doc corrupted file .How to recover unsaved documents WORD? how to view corrupted word files, please help

    It could be Word or even Windows that is having the problem. Before you start trying to restore a backup or repair a file, try opening other documents.
    Try opening your "corrupt" document from another computer. Also you can try to make a copy of corrupted files. (It could work) : http://www.filerepairforum.com/forum/microsoft/microsoft-aa/word/968-i-would-be-grateful-for-any-help-to-repair-or-the-procedures-word-files
    But if nothing helps, you can try to recover it by using DOCX Viewer Tool Download free demo versions of this software from website: http://www.docx.viewertool.com/ It’s
    gonna help.

  • Hi. There is a ghost search bar on my iMac screen which flashes constantly, even during start up and shut down. How can i make this go away? Please help. x

    Hi There is a ghost search bar on my iMac that flashes continually, even during start up and shut down. How can i make this go away? Please help. x

    Please read this whole message before doing anything.
    This procedure is a test, not a solution. Don’t be disappointed when you find that nothing has changed after you complete it.
    Step 1
    The purpose of this step is to determine whether the problem is localized to your user account.
    Enable guest logins* and log in as Guest. Don't use the Safari-only “Guest User” login created by “Find My Mac.”
    While logged in as Guest, you won’t have access to any of your documents or settings. Applications will behave as if you were running them for the first time. Don’t be alarmed by this behavior; it’s normal. If you need any passwords or other personal data in order to complete the test, memorize, print, or write them down before you begin.
    Test while logged in as Guest. Same problem?
    After testing, log out of the guest account and, in your own account, disable it if you wish. Any files you created in the guest account will be deleted automatically when you log out of it.
    *Note: If you’ve activated “Find My Mac” or FileVault, then you can’t enable the Guest account. The “Guest User” login created by “Find My Mac” is not the same. Create a new account in which to test, and delete it, including its home folder, after testing.
    Step 2
    The purpose of this step is to determine whether the problem is caused by third-party system modifications that load automatically at startup or login, by a peripheral device, by a font conflict, or by corruption of the file system or of certain system caches.
    Please take this step regardless of the results of Step 1.
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards, if applicable. Start up in safe mode and log in to the account with the problem. You must hold down the shift key twice: once when you turn on the computer, and again when you log in.
    Note: If FileVault is enabled, or if a firmware password is set, or if the startup volume is a software RAID, you can’t do this. Ask for further instructions.
    Safe mode is much slower to start up and run than normal, with limited graphics performance, and some things won’t work at all, including sound output and Wi-Fi on certain models. The next normal startup may also be somewhat slow.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    Test while in safe mode. Same problem?
    After testing, restart as usual (not in safe mode) and verify that you still have the problem. Post the results of Steps 1 and 2.

  • HT204053 I have two Apple ID's. How do I delete one of them? Please help. Thank you. Dru

    I have two Apple ID's. How do I delete one of them? Please help. Thank you. Dru

    To add to the above...
    From Here   http://support.apple.com/kb/HE37
    I have multiple Apple IDs. Is there a way for me to merge them into a single Apple ID?
    Apple IDs cannot be merged. You should use your preferred Apple ID from now on, but you can still access your purchased items such as music, movies, or software using your other Apple IDs.

  • I down loaded about 100 cds to my library and I can no longer view the downloaded artwork it's shows a black picture or blank. How can I get the artwork back? Please help! Thank you

    I downloaded about 100 cds to my library and I can no longer view the downloaded artwork it's shows a black picture or blank. How can I get the artwork back? Please help! Thank you.

    Hi- apparently I also had a similar moment of madness and thought that 'freeride games' would be fun. Well, so much for that! It added a ton of things to my tool bar, I would like to uninstall it, any suggestions for this one?
    thanks :)

  • I'm getting this problem when trying to update my iphone 3gs it says that the iphone software could not be contacted and I went on youtube got some advise to go into my hard drive to fix the error I have nothing in my host file please help me if you can

    I'm getting this problem when trying to update my iphone 3gs it says that the iphone software could not be contacted and I went on youtube got some advise to go into my hard drive to fix the error I have nothing in my host file please help me if you can this is all new to me.

    Read this: iOS 4: Updating your device to iOS 5 or later
    ... oh I think it is a 3gs or a 3
    This makes a difference. What does it say in Settings > General > About?

  • After upgrading my software i have seem to have lost all my contacts and photos, i did a back up but i have no idea how to get them back on? maybe im illiterate but i dont know how to find it in my itunes? please help!!

    After upgrading my software i have seem to have lost all my contacts and photos, i did a back up but i have no idea how to get them back on? maybe im illiterate but i dont know how to find it in my itunes? please help!!

    http://support.apple.com/kb/HT5824?viewlocale=en_US&locale=en_US

  • Illustrator CS4 wont save files, please help?

    You can edit a file, go to save, close it down, then when you re-open it the changes made have not been saved?? No error message or warning pops up, and it all looks ok like it has saved properly, until you open it up again. This also happens when you use 'save as' command if you use the original file name. If however you type in a different file name - it saves ok. But obviously that is not great as you cant now trust or rely on the save mechanism of the programme, to make sure any changes to artwork have been stored!! I have never seen an issue like this, it is worrying, I hope somebody can help?
    Thanks.
    We are running CS4 on windows7 - yes PC!!!

    We save in EPS, and its not just one file, its a variety of different files and it seems to be random as to which files it does it on, some work fine - some don't. And it can be anything from a minor text change to a colour change, it doesnt seem to matter on the change made, it reacts the same.
    The files are saved over a network connection to a large external hard drive.
    Its really puzzling and now starting to cause problems as we do a fair bit of work in it, and can't trust one of the most important features, and that any changes that have been done have been saved and stored!
    Hope maybe you can help with any thoughts at all.
    Cheers.
    Date: Thu, 24 Jun 2010 03:41:40 -0600
    From: [email protected]
    To: [email protected]
    Subject: Illustrator CS4 wont save files, please help?
    What file format do you save it in?
    What kinds of changes did you make in that file?
    Where do you save the file (removable or network media)?
    >

  • I have iOS 6 on my iPhone. i have linked my contacts with facebook and yahoo, which has doubled or triplicated some of the contacts. how can i integrate them into one? please help. it is getting on my nerves. thanks :)

    I have iOS 6 on my iPhone. i have linked my contacts with facebook and yahoo, which has doubled or triplicated some of the contacts. how can i integrate them into one? please help. it is getting on my nerves. thanks

    click on the contact which you want to integrate, click the edit button scroll down u will find a option called link contacts use it to link it to the duplicate contact

Maybe you are looking for

  • Not supprted resolution 1440x900 for 19" screen on Satellite A110-178

    Hello. My Toshiba A110-178 (with chipset Mobile Intel 945GM Express) does not support Widescreen 19" resolution 1440?900. How i cant adjus this resolution. Thanks Ben Message was edited by: Kuleshov

  • Production Order for variant subassemblies

    Hi all, I have a scenerio were there is header material called A. It has sub-assemblies C,D,E. Each subassemblies have lot of variations. So the User does not want to create individual Material Master for these variations. But the user wants to book

  • Windows Server 2008 Ent to Windows server 2012 R2 std Migration

    Dear All, We have windows server 2008 x64 Ent with SP2 it's working fine and perfectly . Presently we implemented new data center also we installed windows server 2012R2 Std . we would like to migrate windows form old data center to new data center .

  • Can't login using Firefox. (Mac OS X)

    I can't login to Adobe or the forum using Firefox (v30.0) Mac, which is my main browser. I'm only logged in right now using Safari. Here is a screen shot of the errors in the error console. I see this problem in archived threads, and they seemed to h

  • Combine the data of two DSOs into one

    Hello experts, how to load the data of two DSOs into a single one using transformations and DTPs? Example: DSO A keyfields: X,Y,Z / attributes M,N,O DSO B keyfields: X,Y,Z / attributes P,Q DSO C keyfields: X,Y,Z / attributes M,N,O,P,Q  (result should