Quick question using FileWriter

Hi all!
I have a file f that I wish to write to my C:\testarea directory, I was just wondering how I accomplish this using FileWriter. This is what I have so far:
BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\testarea"));But then how can I pass my file f to the writer to write it. Alternatively I could have done:
BufferedWriter writer = new BufferedWriter(new FileWriter(f));But then how can I specify where I want it to write to?
Many thanks for your help in advance!

Remember that directories are files, too. If C:\testarea is a directory, then executing the following expression:
new FileWriter("C:\\testarea")Causes the following runtime exception:
Exception in thread "main" java.io.FileNotFoundException: C:\testarea (Access is denied)
The FileNotFound- part is misleading: the error is "Access is denied": you typically don't have write
access to a directory. The above writer is attempting to write to the directory file, versus writing to a given
file in that directory.
I think you also have some basic misunderstandings with regard to relative paths. If you create a file object::
File f = new File("file.txt");Well, as the File API states:
By default the classes in the java.io package always resolve relative pathnames against the current user
directory. This directory is named by the system property user.dir, and is typically the directory in which the
Java virtual machine was invoked.
The following program demonstrates this:
import java.io.*;
public class Test {
    public static void main(String[] args) throws IOException {
        File f = new File("file.txt");
        System.out.println("user.dir = " + System.getProperty("user.dir"));
        System.out.println("path = " + f.getAbsolutePath());
}So how to you write to file file.txt in directory c:\testarea? In any of the following ways:
String dirPath = "C:\\testarea";
String filename = "file.txt";
String path = dirPath + File.pathSeparator + filename;
File dir = new File(dirPath);
File f1 = new File(dir, filename);
File f2 = new File(path);
File f3 = new File(dirPath, filename);
BufferedWriter w = new BufferedWriter(new FileWriter(f1_or_f2_or_f3));
BufferedWriter anotherw = new BufferedWriter(new FileWriter(path));

Similar Messages

  • Quick Question using REGULAR EXPRESSIONS

    Hi Experts,
    BANNER                                                                         
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production         
    PL/SQL Release 11.1.0.7.0 - Production                                         
    CORE     11.1.0.7.0     Production                                                     
    TNS for 32-bit Windows: Version 11.1.0.7.0 - Production                        
    NLSRTL Version 11.1.0.7.0 - Production                                         
    5 rows selected.I will be getting multiple values as input which will be separated by "[#|#]"
    I need to identify and splitup values based on it and to do my process.
    I have already asked similar question, but still struggling with that since the values i get in the Text is not restricted to any specific character so that not works on replacing the separator "[#|#]" by some character and using REGEXP_SUBSTR.
    I need to work around some thing like below code,
    DECLARE
        vInfo   VARCHAR2(4000) := 'cropX=42,cropY=0,Text=`$@@@@@@####[##][##][#|#]cropX=42,cropY=0,Text=`$@@@@@@####[##][##]';
        vDet    VARCHAR2(4000);
        vPos    INTEGER := 1;
        LOOP
            * vDet    := REGEXP_SUBSTR(vInfo,'[#|#]',1,vPos); *
            EXIT WHEN vDet IS NULL;
            vPos := vPos+1;
            -- My Process Here based on splitted values here
            DBMS_OUTPUT.PUT_LINE(vDet);
        END LOOP;
    END;  Suggest me to work out this.
    Thanks,
    Dharan V

    B'coz
    Not just one value which i need to split. There are so multiple variables i need to with different separator.
    Thanks for suggestion, I have STR2TBL already installed and working with that.
    But not sure whether i can combine my requirement with that and to work out this ?
    DECLARE
       vId      VARCHAR2(50) := '1,2,3';
       vIdValue INTEGER;
       vName    VARCHAR2(40) := 'Name1,Name2,Name3';
       vInfo    VARCHAR2(4000) := 'cropX=42,cropY=0,Text=`$@@@@@@####[##][##][#|#]cropX=42,cropY=0,Text=`$@@@@@@####[##][##]';
       vDet     VARCHAR2(4000);
       vPos     INTEGER := 1;
    BEGIN  
        LOOP
            * vDet      := REGEXP_SUBSTR(vInfo,'[#|#]',1,vPos); *
            vIdValue    := REGEXP_SUBSTR(vId,',',1,vPos);
            EXIT WHEN vDet IS NULL;
            vPos := vPos+1;
            -- My Process Here based on splitted values here
            DBMS_OUTPUT.PUT_LINE(vDet);
        END LOOP;
    END; 

  • Quick question; Use of static{}

    Other than knowing it is useful to enable object interaction with methods outside of main, I have never come across
    public static char[] chars;
    public static String charArray = "abcdefghijklmnopqrstuvwxyz0123456789";
    static {     // Code in question
          chars = charArray.toCharArray();
         }I must be missing something but I am glad I came across this

    Ebodee wrote:
    Thank you jverd, I learned something about Java today. I ran the code and my only question is why would the JVM begin initiating Main code, then the second static initializer, then the remaining Main statement?There's only one static initializer. And one instance initializer. The static initializer is executed once, when the class is loaded/initialized. The instance initializer is executed whenever we create an instance (e.g. new Foo()).
    If we execute java -cp . Foo on the command line, we're telling the JVM to execute the main() method in class Foo.
    The JVM has to load and initailize the class before it can use it. This is when the static initializer is run. ("static init"). It does this once for the class.
    Now that it has loaded the class, it can call the main() method. The first thing this method does is print out "main, foo1".
    Next we crate a Foo object. When we create an object, we specify a constructor to execute. Immediately before that constructor, any instance initializers execute ("instance init"). This happens once for each object we create. Then the c'tor body is excuted ("constructor").
    Now we print "main, foo2", then create another Foo object, which once again runs the instance initializer and the constructor.
    I know Main is a thread but would that be the reason?Eh? There's no Main in the code I provided. There's a method called main, not Main, but it's a method, not a thread. All code in Java runs inside a thread, even if you don't explicitly create or start any threads.
    I don't really understand your question.
    Edited by: jverd on Sep 23, 2010 3:24 PM

  • Quick question using BatchAction

    I'm an FDM newbie, so some of the question I'm asking may seem to be trivial...
    Is it possible to trigger an event from BatchAction? I wrote some code in BatchAction and want to trigger specific events (basically I want to mimic the steps I take manually from the web the import, validate, export and check steps)
    thanks,
    cg

    The type of questions I'm asking is not documented in any guides, as it should not be. The api guide states what can be done, not how it can be done. Understanding the 'how' comes with FDM experience, which I do not have, hence my postings.
    Sorry, I got sidetrack, so back to my posting:
    Currently, a user logs on to FDM via web, clicks on Import from Workflow, selects a file, and once processed, saves that file in Excel. Note that there are custom scripts (expression?) in metadata's Import Format screen which do various things such as format fields, etc. there are a lot them.
    I would like to automate this since now, this task will become a daily occurance. I would also like to maintain the existing scripts/expressions used during the workflow->import process, and make use of them instead of recreating the logic when generating a new file. I know I can use the fLoadAndProcessFile from the api call, but how do i incorporate this into the batch script I've written, etc...
    All this with using the Batch Loader and not a custom script. Custom script will come later...
    I get the big picture, it's the little pictures I'm trying to piece together...
    thanks.
    Edited by: cg on Dec 2, 2011 7:29 AM

  • Quick Question: When to use ( ) and when to use [ ] and why the ( *)

    Hi all,
    A quick question that i'm sure is very simple but is slightly confusing me. I've just started trying to learn Objective-C and am a little confused by ( ) and [ ].
    I get that you use the [ ] brackets when you want something specific from an object, i.e.
    [ textField textColor ]
    and that you use ( ) brackets for things like:
    if ( x == y) {
    But I get confused when I see things like:
    NSLog(@"some text here");
    Why does that get ( ) brackets and why is it not [ ].
    Also another point of confusion, creating methods... Why are some methods done like:
    - (void)awakeFromNib
    And others done like (with the additional "*" added):
    - (NSString *)stringvalue
    As I said, I'm sure this is very simple and obvious, but it is confusing me slightly.
    Thanks in advance!

    Adam:
    As you already know, square brackets are used to send a message to an object, so if a object like myObject implements the method -doSomething, you can call it with:
    \[myObject doSomething\];
    The other use square for brackets have is to index C-style arrays, such as:
    aValue = anArray\[10\]; // Get the 10-element of an array
    However, because C-style arrays are rarely used in Cocoa applications (use NSArray instead) you will not see this situation often.
    Parenthesis in expressions are used to group and prioritize, such as:
    x = 10 * (3 + 5); // x = 80
    If () statements use it to delimit the test expression. Same with while (). for () uses it to enclose the limits and increment statements, etc.
    The other important use of parenthesis is in calling a C function:
    result = foo(3);
    means that you are calling the function named foo with the argument 3, and storing the the return value in the variable 'result'. This is different from a message because a C function is not a method of an object. They exist independently of any objects. NSLog() is a function defined within Cocoa but it is not a method. So, you call it with the traditional C function call syntax. Cocoa defines other functions like NSStringFromRect(), which takes an NSRect as argument and returns a pointer to an NSString.
    And that leads me to your last question. Some methods return simple types, like int, float, or void (i.e. returns no value). These methods will have prototypes like:
    \- \(void\)returnNothing;
    \- (int)returnInteger;
    Other methods return pointers to types, like:
    \- (int \*)returnPointerToInteger;
    \- (void \*)returnPointerToAnything; // In obj-C one typically uses id instead of void*
    Returning whole objects from methods has problems and it is better to just return a pointer (the address in memory) instead:
    \- (NSString *)makeAString;
    The method above returns a pointer to an NSString rather than the entire object.
    Good luck with your learning,
    Juan-Pablo
    Message was edited by: Juan Pablo Claude

  • Hi, I have quick question about use of USEBEAN tag in SP2. When I specify a scope of SESSION for the java bean, it does not keep the values that I set for variable in the bean persistent.Thanks,Sonny

     

    Make sure that your bean is implementing the serializable interface and that
    you are accessing the bean from the session with the same name.
    Bryan
    "Sandeep Suri" <[email protected]> wrote in message
    news:[email protected]..
    Hi, I have quick question about use of USEBEAN tag in SP2. When I
    specify a scope of SESSION for the java bean, it does not keep the
    values that I set for variable in the bean persistent.Thanks,Sonny
    Try our New Web Based Forum at http://softwareforum.sun.com
    Includes Access to our Product Knowledge Base!

  • Hi guys. Just a quick question. My wife has a Mac Book Pro and when she is browsing the web she can use a two fingered gesture to go back to her previous page (by swiping from right to left). Is there any way to set that up on my iPad Mini. Many thanks.

    Hi guys. Just a quick question. My wife has a Mac Book Pro and when she is browsing the web she can use a two fingered gesture to go back to her previous page (by swiping from right to left). Is there any way to set that up on my iPad Mini. Many thanks.

    Not in the Safari browser she can't. That is not supported on the iPad. There are other mobile browsers that do have that functionality - one is iCab Mobile.
    https://itunes.apple.com/us/app/icab-mobile-web-browser/id308111628?mt=8

  • Formatting output using FileWriter

    Hi Experts,
    Just a quick question, I have a FileWriter which grabs some text from a JTextPane and then outputs it to a pre-defined textfile, all works well until I open the textfile, instead of the nice formatted text I get from JTextPane, it all spans one line!
    Anybody out there know how tof ormat the output, so it looks exactly like the JTextPane?
    Thanks,
    Reacz.

    Get the text from the JTextPane and write it to the FileWriter one line at a
    time. Wrap the FileWriter in a BuffreredWriter so you can take advantage of
    the latter's newLine() method.
    Anybody out there know how tof ormat the output, so it looks exactly like the
    JTextPane?Strictly speaking the output (a file) doesn't look like anything. It only looks like
    something when you view it in some application or other. If you separate
    each line of output with newLine() then you will be using the new line separator
    that is the "default" for your OS. This at least maximises the chances of it
    being right for whatever application you are using to view the file.

  • Report Generation Toolkit Error Quick Question

    Hi,
         I created the most awesome LabVIEW report ever at my desk using a trial version of the RGT and Office 2003.  I took this to my production machine and ")@#(&%(*#^%()^!!!"  The production machine has office 2007 and a fully licensed version of the RGT.  Both machines have LabVIEW 8.6.0.  I've read all the stuff about these errors and something about classes and dll's and whatnot's.  So my quick question, is:  Instead of matching the versions of Microsoft Office as recommended, can I just rewrite from scratch the VI that creates this world's most awesome LabVIEW report on the production machine to create the same effect? 
    Solved!
    Go to Solution.

    Hi 
    Quick Answer: Probably
    Slower answer: Microsoft changed a lot of things behind the scenes in Office 2007, but the Report Generation toolkit version 1.1.3 supports Office 2007 so you should be good to go. Depends on what functions are included in your VI. Liek the read me says "Several default settings in Microsoft Office 2007 differ slightly from previous versions. Reports you generate using Office 2007 might look different than reports you generate from other versions of Office because font sizes, cell sizes, and so on, differ."
    Best Regards
    David
    NISW

  • Two quick questions about Library after moving beginning on a new computer

    Hi there,
    I just moved from Windows to Mac, meaning I had to move my iTunes library from the old PC to my new MBA.
    Just a couple of quick questions.
    1. When I started iTunes on my new Mac, in the preferences I directed the media folder to the folder with all my itunes music/podcasts etc, and then I imported the Library XML file.  Is this incorrect? Should I have imported a different file? Should I have used the itl file instead? 
    If so, should I delete the library and start again?  (if this is the case, please suggest the best way of doing this without affecting my media)
    - a kind of sub-question to this one:  some of the media files arent showing up in the iTunes library, but they are in the media folder on the ext HDD.  Is there a way I can find out which ones havent been recognized by iTunes?  Whats the best way of getting them in to my library?
    2. Pretty much half of my podcasts have not been loaded in the new iTunes.  The ones that havent were ones that I subscribed to on my iPhone, whereas the ones that show up in iTunes were ones I downloaded from iTunes.  When I connect my iPhone and sync it with iTunes, will those podcasts show up in iTunes?  Or is there a risk that they will be deleted from my iPhone?
    Cheers,

    The .xml is lacking some information such as ratings, date added, and play count.  Using the .itl includes this information but cannot be imported using the method you did.
    A complete library is everything in the iTunes folder.  By using the method you did you left the artwork behind in the artwork folder on the other machine.
    Selecting the media folder in preferences does not get iTunes to recognize the media.  All it does is tell iTunes to start storing new media in that location.
    Using the method I outlined nothing will be missed (with the exception of WMA) because you aren't rebuilding your library, you are using the one that already exists.
    You don't have to re-copy everything as long as you get the stuff you missed and re-assemble it all as it was before except not on the Mac.
    What are the iTunes library files? - http://support.apple.com/kb/HT1660
    More on iTunes library files and what they do - http://en.wikipedia.org/wiki/ITunes#Media_management
    What are all those iTunes files? - http://www.macworld.com/article/139974/2009/04/itunes_files.html
    Where are my iTunes files located? - http://support.apple.com/kb/ht1391

  • Quick question re select-options

    Hi
    I am relatively new to ABAP but have a quick question:
    I need to create a select-options which does the following:
    1. Allows ONLY "equals" signs
    2. Disallows intervals
    3. Disallows the use of ranges in the multiple selection box.
    4. Allows multiple individual selections.
    I can achieve most using the following:
    select-options s_knvh for knvh-kunnr no intervals.
    However, this still allows ranges using the multiple selection box, and also allows the "not equal to" option.
    Adding the "no-extension" syntax simply removes my ability to use multiple individual entries.
    Any ideas?
    Thanks
    Jon

    Use this FM.
    SELECT_OPTIONS_RESTRICT

  • A quick question about WebDynpro SLD and R/3 with concurrent users

    Hello ,
    I have a very quick question about Webdynpros and SLD connecting to an R/3 system, when you configure a webdynpro to connect to an R/3 system using SLD, you configure a user name and password from the R/3  for the SLD to use. What I would like to know is when I have concurrent users of my webdynpro, how can I know what one user did in R/3 and what another user did? Is there a way for the users of the web dynpro to use their R/3 credentials so SLD can access the R/3? Like dynamically configuring the SLD for each user?
    - I would like to avoid leaving their their passwords open in the code ( configuring two variable to get the users username and password and use these variables as JCO username and password )
    Thanks Ubergeeks,
    Guy

    Hi Guy
    You will have to use Single Sign On to achieve this. In the destination you have defined to connect to R/3 , there is an option to 'useSSO' instead of userid and password. This will ensure that calls to R/3 will be with the userid that has logged into WAS. You wont need to pass any passwords because  a login ticket is generated from WAS and passed on to R/3. The userid is derived from this ticket.
    For this to happen you will have to maintain a trust relation ship between R/3 and your WAS ,there is detailed documentation of this in help files. Configuration is very straight forward and is easy to perform
    Regards
    Pran

  • QUICK QUESTION ABOUT PORTS

    Hi, I have a quick question about port forwarding/mapping. My question, lets say I am running MSN messenger, who's ports are 6880-6900. But lets say I am running a torrent application or something else that requires those ports. If both applications were running at the same time, would this cause interference with them on the same ports or now. Thanks
    Nathan

    Normally, only one application can listen to a specific port number at a time. If MSN is grabbing those 21 ports then your torrent app won't be able to run.
    However, most apps don't work that way - even if they use multiple ports, they don't use them all at the same time, so MSN might use 6880 when it starts up, leaving the others open for other applications to use if needed.
    Only experimentation will answer that one.

  • Quick question, where to put global variables

    Very quick question:
    where is the best place to put global variables,
    (e.g. a flag that turns on debug mode)
    if they are needed by the entire application?
    I'm guessing they should be placed in their own class.
    But should I make them public static final constants,
    and just do Globals.MYCONSTANT
    OR should i do "implements Globals" in all my other classes?
    The first way seems simpler and more logical,
    but in the examples for JSDT, they use the second technique.
    Any thoughts?
    thanks! =)

    I would suggest either creating a properties file for your globals, or adding them to the system properties at startup. Placing items like debugging tags in your code means that you have to change the code, recompile, and rejar before your change is implemented. Using system properties means that you simply have to change your command-line options (i.e., from -Dmyapp.debug=true to -Dmyapp.debug=false).
    Shaun

  • Quick Question about fade effect

    Quick Question:
    If I wanted to add a Fade Effect from one state to another
    when a button is pressed.
    How would I do that within the code?

    quote:
    Originally posted by:
    atta707
    You can do something like on the click of the button:
    var fader:Fade = new Fade(targetUIComponent);
    fader.duration = 1000;
    fader...;
    fader.play();
    or listen for currentStateChanging event and write the same
    similar code.
    or define transitions from one state to another like:
    <mx:Transition id="toOneOnly" fromState="*"
    toState="OneOnly">
    <mx:Sequence id="t1" targets="{[p2]}">
    <mx:Iris showTarget="false" duration="350"/>
    <mx:SetPropertyAction name="visible"/>
    <mx:SetPropertyAction target="{p2}"
    name="includeInLayout"/>
    </mx:Sequence>
    </mx:Transition>
    Hey,
    I would like to use the "transition from one state to
    another", but if you can explain each part for me that would be
    helpful.
    If you can comment on each line of that code that would help
    thanks

Maybe you are looking for

  • How to convert this into alv display and also change parameterstoselect opt

    tables :mara,marc,stpo. parameters: p_werks like t001w-werks obligatory, p_matnr like mara-matnr obligatory. *select-options : p_matnr for mara-matnr obligatory. *parameters: p_werks like marc-werks obligatory, *p_matnr like marc-matnr obligatory. co

  • Transaction F-53 Post outgoing payments

    Hi. I have used BAPI_ACC_INVOICE_RECEIPT_POST for posting of invoice receipt / outgoing payment with success. But I futhermore want to mark my reference document / received invoice as cleared. Technically I wants to fill the clearing information on t

  • Solaris 10 on Dell Desktop

    Hi, I offered to install Solaris 10 x86 on a friends desktop so they could do a Sun JES trail. The system they gave me is a Dell Dimension 3000 which is a P4 3 GHz with 1 GB of memory - should be fine for their trial. However, OS doesn't seem to reco

  • Identical item codes in two different warehouses

    We currently have several items that exist in two warehouses. We are using SAP Business One, 8.81 PL09, DTW 88.1.7. All of our items from warehouse A have pulled without any errors. We are using a ItemGroupCode of 100 (default) for both warehouses, a

  • Cannot distribute secured form.

    Hi Everyone, Using Livecycle Designer ES2 9, with Acrobat Pro 10.0.3. Standalone implementation. When attempting to distribute a secured form, Acrobat displays "Acrobat is unable to distribute this form because of the form's security settings." The f