Write to My Documents

I'm trying to write to My Documents, but I can't figure out how to make it generic. Each pc has at least 2 users on it, I want to write to the My Documents folder for the current user. It works for every other directory except for My Documents
Any suggestions?
Thank you in advance
try {
                    String[] contactArray = parseDatFile(fc.getSelectedFile());
                    Document document = createXMLDocument(contactArray);
                    saveToXMLFile(
                    document,
                    new File(
                    "C:/Documents and Settings/john.doe/My Documents/OLCS/",// not sure where the default location is yet! Change code below when defualt is known.
                    "contacts-list_migration.ctt"));
                } catch (Exception exc) {
                    File f = new File("C:/Documents and Settings/john.doe/My Documents/OLCS/");// not sure where the default location is yet!
                    boolean yes = true;
                    yes = f.mkdir();

You could use this utilty class:
import java.io.*;
public class Win32Util
    private static final String PERSONAL_FOLDER_CMD = "reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\" /v Personal";
    private static final String REGSTR_TOKEN = "REG_SZ";
    private static String currentUserPersonalFolderPath;
    public static String getCurrentUserPersonalFolderPath()
        if (currentUserPersonalFolderPath != null)
            return currentUserPersonalFolderPath;
        try
            Process process = Runtime.getRuntime().exec(PERSONAL_FOLDER_CMD);
            StreamPumper pumper = new StreamPumper(process.getInputStream());
            pumper.start();
            process.waitFor();
            pumper.join();
            String result = pumper.getResult();
            int p = result.indexOf(REGSTR_TOKEN);
            if (p == -1)
                return null;
            currentUserPersonalFolderPath = result.substring(p + REGSTR_TOKEN.length()).trim();
            return currentUserPersonalFolderPath;
        catch (Exception e)
            return null;
    static class StreamPumper extends Thread
        private InputStream is;
        private StringWriter sw;
        StreamPumper(InputStream is)
            this.is = is;
            sw = new StringWriter();
        public void run()
            try
                int c;
                while ((c = is.read()) != -1)
                    sw.write(c);
            catch (IOException e)
        String getResult()
            return sw.toString();
}Just do Win32Util.getCurrentUserPersonalFolderPath()

Similar Messages

  • How do I change the color of font in a fillable form in Adobe Reader? How can I check if the writer of the document has given permission to edit color and not just add text?

    How do I change the color of font in a fillable form in Adobe Reader? How can I check if the writer of the document has given permission to edit color and not just add text? Please help! I'm technologically challenged.

    Most forms (99% or more) are created for simple text input, where you cannot change anything.
    The creator of the form could allow Rich Text input (which allows you to change font, text size, color, etc.), but frankly I have never seen such a form, and I wouldn't know how they look.  But I'm sure they would show some kind of controls to alter the text appearance.

  • I am looking for a app which enables me to write in a document on my iPad2, for instance in word documents

    I have a iPad 2. Someone told me there would be a App which i can download that enables me to write in a document on my iPad, on the screen. For instances during a business meeting. Then it is not necessary anymore to print the document when i want to make notes in the Word-document.
    Does anybody know the name of the App and where i can find it?
    Thanks,
    Bert Ramakers

    Hi Bert...
    I like Penultimate >  http://itunes.apple.com/us/app/penultimate/id354098826?mt=8
    It's not a word document in itself but you if you have Pages installed on your iPad you can export Penultimate notes to Pages.
    http://www.apple.com/ipad/from-the-app-store/apps-by-apple/pages.html

  • How do you write on the documents useing using work space

    how do you write on the documents using work space

    What type of documents are you trying to write on?

  • How to write an xml Document to a flat file using JAVA....

    Can any one help me out.....
    How to write a XML Document to the current filesystem using JAVA....
    without using com.sun.xml.tree.*....
    Document xmlDoc;
         Node rows = (Node) xmlDoc.createElement("ROWS");
    xmlDoc.appendChild(rows);
    and i have to write this xmlDoc to a file called(abc.xml) for further use...

    Have you considered using JDOM? ( www.jdom.org )
    The XMLOutputter class can write the Document to a file. ( The Document however will be an org.jdom.Document object ).
    If you are weary of a new API, you could just create a new File object called abc.xml and stream the data from the XML Document you have to this new File object.

  • Write & Modify XML Document on Midlet

    please help me, how to write & modify xml document on Midlet????
    I use KXML1.2 but it can't do write & modify. I read this documentation.... KXML just only read XML document....
    so everybody can help me.....
    please send your comment on my email... because my internet bandwith is so low. It's long time when I open this forum.
    thanks very much

    Check out with kXML 2
    Cheers,
    Rohan Chandane

  • Mac desktop. 10.6.8. Text edit. Not locked. Read and write. Still, documents are locking when they are moved from desktop to another folder on the server. Techies can't figure it out here. What am I not doing?

    Mac desktop. 10.6.8. Text edit. Not locked. Read and write, not read only. Documents are locking when they are moved from desktop to another folder or saved directly into that folder on the server. Not happening with anyone else but me and the boss's computer so has to be in the properties for my text edit software. Techies can't figure it out after trying for two weeks. Boss can do a cut and paste and put into a new document, but that's starting to become a problem.

    Mac desktop. 10.6.8. Text edit. Not locked. Read and write, not read only. Documents are locking when they are moved from desktop to another folder or saved directly into that folder on the server. Not happening with anyone else but me and the boss's computer so has to be in the properties for my text edit software. Techies can't figure it out after trying for two weeks. Boss can do a cut and paste and put into a new document, but that's starting to become a problem.

  • How can I read and write a Word document keeping the formatting properties

    Hi everybody,
    I am reading a word document and writting it into a XML document. I need to keep the text formatting. Which properties and how I
    can access them using HWPF POI?

    Note: I am already using HWPF POI with java to read the word document.

  • Write off FICA documents with no segments after New GL has been activated

    Hi Gurus,
    The scenario we are facing is as follows"
    The client had already implemented FICA as part of its legacy, but SAP FICO was not implemented. As part of the new framework, we are implementing SAP FICO as well, while at the same time New GL is now being activated.
    All ancillary configurations have been maintained for deriving profit center/segment information on main and sub transactions through use of CO Account assignment key.
    Issue:
    The issue we are facing now is that, while writing off (FP04) any FICA document which has a profit center/segment information, we are able to write it off. But any FICA document which does not have segment information, we are getting the error "Segment Missing"
    Probable Solutions:
    1) Tried maintaining the  value as "2" (Account Assignment) at the following node:
    FICAIMG-->Business transactions--> Define specifications for Write-offs
    This solution did not help us in writing off the FICA document
    2)Custom logic in event 5030?
    Custom logic can be maintained in the FM at event 5030, where we should be able to derive the profit center/segment info. based on the business area
    Please let me know if any other options can be tried and also if the custom logic at event 5030 should help us resolve the write off issue?

    Hi, I have the same laptop and had the same problem.
    I have solved it by adding the following arguments to the kernel command line:
    acpi_osi=Linux acpi_backlight=vendor
    Note: acpi_osi only did the trick, but then the backlight service fails. acpi_backlight fixes the service.

  • Need to write on a document that i have received via email.  how do I do this??

    how do i enable a document that i have accessed on line so that i can write on it?????

    What type of document are you attempting to sign?  Is it a PDF? A Word document? Something else?
    Do you have the document on your computer?

  • Write to word document from oracle plsql

    Hi,
    Please provide methods to create and write to a word document from ORACLE PLSQL.We tried using UTL FILE package but it writes as ascii text.

    Divs wrote:
    The server m/c operating system is unix.so we need to invoke the procedure from Unix Os.In that case - not possible. For Windows COM (Component Object Model) to work, Oracle database need to be able to call and load the COM dynamic link libraries.
    Not to say that it is not possible. Have never used DCOM (the Distributed COM interface), and not exactly sure what it requires. Assuming that DCOM is not usable from a Linux perspective, you can still provide a manual interface. You create a NT tcp/ip service that exposes the COM interface calls that you need - in a secure fashion (even better - you can provide a higher level abstraction layer for the COM interface that does the specific job you need to be done).
    From Oracle you can then use PL/SQL's UTL_TCP package to open a connection to it and via this service craft a Word document on that Windows server.
    Are there web services for MS Office? I know Google is pushing that aspect hard (and embroiled in lawsuits with the US government and Microsoft about tender awards in this aspect). Now if Microsoft has "+office-on-the-web+", then one can create a Word document via a web browser. This means that there is an underlying web service - and that this can be called and used. The Evolution (Open Source Mail Reader) project for example uses the MS Exchange web service interface to provide a seamless interface to Exchange mail accounts (have used this everyday for a number of years now).
    The real question I would however ask is why Word specifically? Why not a more common format like PDF? You can even consider generating XML instead. Both Microsoft and Open Office and others are supporting XML formatted word processing documents (as oppose to older proprietary and binary formats).
    And why not use a Report Writer? I'm a big fan of doing as much as possible in Oracle (using PL/SQL most of the time). But certain things, like generating Word-style documents would be better done (and more flexible too) using a Report Writer.

  • Workflow write-off of documents

    Hi Gurus,
    I have a requirement where in i will have to develop a custom program and it will fetch all the docs to be written-off and then it will trigger a workflow and workflow should validate (it will see if the doc can be written off by the user who kicks of the workflow)the docs selected by the program , if yes then we have to get all the cost centre details , GL account , amount etc in one of the steps in workflow and then the document is written-off using F-30(whatever process is followed in f-30 to write offshould be done as a background method) , if the user is not authorized then a work item goes to his manager for approval and he should see the item through FB03 link , if he approves it should happen through F-30((whatever process is followed in f-30 to write offshould be done as a background method) or else a mail is sent to the initiator.
    please can some one suggest if there are any BAPIs or BTEs that can suffice my need.
    thanks
    C S Anand.

    Hello Mahendra,
    please have a look at the following link: <a href="http://help.sap.com/saphelp_media472/helpdata/en/69/1b8c82950111d2ac740000e829fbfe/frameset.htm">Liability Account Transfer</a>
    I think this describes it pretty well.
    Tim

  • How do I write a PDF document on my ipad

    So just new to all this, I want to write papers on my iPad from class and be able to print  them out or send to my teachers. What is the best app for that?

    Your going to have to be far more specific than wanting to "write papers". What degree are you working towards? If its something like Chemistry for example, then writting papers in anything that cannot present the chemical formulas properly would be unwanted.
    Thanks
    Jason

  • How to write-protect a document at the time it is opened?

    is it possible to request a password from a user at the time he is opening a document (the password "quality" does not matter - it can be a string predefined in a macro), so that in the case the password is not submitted correctly, a document is forcefully opened in a read-only mode, allowing someone else to open it with password in a full-access mode?
    Thanks!

    Hi shortwedge3,
    You can use [https://addons.mozilla.org/en-US/firefox/addon/opendownload-10902/ OpenDownload2] extension to get '''Run''' option while downloading files using '''Firefox'''

  • How do I just write a word document or something?

    I just got my first Mac from always using PC's. I want to type a word document or something and cannot find how to.

    you need to install a word processing program, such as Pages, Word, or an open source program such as LibreOffice.

Maybe you are looking for

  • Plot xy graph using random number generator

    How do i plot xy graph dynamically every 5 seconds with a random number generator? X axis : Time Y Axis : Random number generator

  • Ws reliable message in OSB

    To utilize WS-ReliableMessaging in OSB, I created a OSB proxy by setting Protocol to ws and Get All Headers to Yes. When a message arrives, I want to extract all the header information in the message flow by querying $header. $header is always empty.

  • Safari Crashes when downloading videos..Help :o(

    Hi Guys / Gals Im new here and have been having some problems. Im writing a project for college and will be using some clips from youtube in it (dont worry its all under the fair use act lol) and for some reason anytime i try to down load either dire

  • Completely PC-less

    Hello, I just purchased an iPAD2 and am looking to see if there are resources I can use to reach my goal of becoming PC-less.  I love the functionality of the iPad and would like this to become my one source for all my business needs.  I specifically

  • Imported slides from PowerPoint

    Does anyone knows if all the transitions and effects I can apply into a Powerpoint presentation will remain the same after I import the whole presentation to Captivate? I tried, but seems it won't work.... any ideas?