Creating a text file in an oracle directory

Hello all,
I created a directory in oracle called sampledata (create directory sampledata as 'c:sampledata'). How do I create a new text file in that directory? That's it.
Thanks,
Ad

I created a directory in oracle called sampledataYou mean you created with sys, right? I think only sys can create directories. Make sure you grant privileges to your user. So let's walk trough this:
connect sys@orcl as sysdba;
create or replace directory temp_directory as 'c:\temp';
grant read, write on directory temp_directory to scott;
connect scott@orcl;
declare
  output_file utl_file.file_type;
begin
    output_file := utl_file.fopen('DIR_TEMP', 'test_file.txt', 'w');
    utl_file.put_line(f, 'Testing output file');
    utl_file.fclose(output_file);
end;
/hth,
gleisson henrique
I granted priveleges to a different directory that I created. Take a look here:
http://www.adp-gmbh.ch/ora/sql/create_directory.html
Pretty good examples.
Message was edited by:
Gleisson Henrique

Similar Messages

  • HOw to create a text file in the given path and delete it after the use?

    Hi all,
    I am trying to create a text file at the given path and delete the created file after the use.
    I am using following code.:
    import java.io.*;
    // write binary data as characters
    public class RanIO {
                                            public static void main(String f[])
                                                      // First illustrate append
                                                      String lineSep = "\n";
                                                      try {
                                                                     File temp= new File("C:/Ash","cute.txt");
                                                      boolean ch=temp.createNewFile();
                                                      if(ch)
                                                           System.out.println("file created");
                                                      else
                                                      System.out.println("file Not created");
                                                      //writing to file
                                                 /*     PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter("cute.txt",true)));
                                                      p.print("Emp NO");
                                                      p.close();*/
                                                                // Open fileWriter in append mode
                                                                               FileWriter fos = new FileWriter(temp, true);
                                                                               BufferedWriter bw = new BufferedWriter(fos);
                                                                               PrintWriter pw = new PrintWriter(fos);
                                                                               double d=550;
                                                                          // lineSep = System.getProperty("line.separator");
                                                                          pw.print("Hello");
                                                                          //pw.print( lineSep );
                                                                          pw.print( d );
                                                                          pw.close();
                                  boolean det=temp.delete();
                                                 if(det)
                                                      System.out.println("File deleted");
                                                 else
                                                      System.out.println("File not deleted");
                                                 } catch (IOException ioe)
                                                                System.out.println( "Append IO error:" + ioe );
    My problem:
    1)
    I am not able to write to the file. I want to know, where i am going wrong.
    It is giving error message like
    "Canot resolve Symbol: temp,"
    But, FileWriter Constructor should accept a File type parameter.
    here temp is a file parameter.
    If i am not using file=new file();
    i can't delete the file after the use. i.e if i use
    PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter("cute.txt",true)));
    how can i delete cute.txt after the use?
    2)
    I am not able to write to the text file. file is created but, a blank file.
    "Hello" is not written into the text file.
    can anyone help me in this regard
    Thanks in advance
    Ashvini

    Thank you Ram,
    But, i want to create a text file in Append mode.
    for that i used
    FileWriter fos = new FileWriter(temp,true); But, it is not accepting FileWriter constructor in
    this format. if i use
    FileWriter fos = new
    FileWriter("c:/ash/cute.txt",true); it works fine. !!!!!Here's the javadoc
    public FileWriter(File file,
    boolean append)
    throws IOExceptionConstructs a FileWriter object given a File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning.
    Parameters:
    file - a File object to write to
    append - if true, then bytes will be written to the end of the file rather than the beginning
    Throws:
    IOException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
    Since:
    1.4
    Are you using jdk.13 or lower ?
    >
    ONe more doubt, Does flush method deletes a file?
    if not, then i need to use
    File temp=new File("c:/ash/cute.txt");
    FileWriter fos = new FileWriter(temp,true); //which
    is again a problem
    if(temp.delete())
    out.println("File is deleted");
    }I don't know whether i am taking it wrong ! or
    anything wrong with my coding ! but, after creating
    and writing data into a text file. I must delete it
    as it contains confidential informations.
    Regards,
    Thanks.'flush' writes to a file immediately. Else you should explicitly call 'flush' to write contents from buffer to underlying source.
    javadoc again
    PrintWriter
    public PrintWriter(Writer out,
    boolean autoFlush)Create a new PrintWriter.
    Parameters:
    out - A character-output stream
    autoFlush - A boolean; if true, the println, printf, or format methods will flush the output buffer
    cheers,
    ram.
    Question; What do you gain by opening a file, writing to it and deleting it in the same program ?

  • Create new text file in UTF-8 format by default

    I'm working a lot with UTF-8 text files and mainly in this format. It's becoming annoying when I have to manually save every text file as UTF-8.  After several trial-and-errors, I've made up a procedure that I've put in a blog. I think I could share
    it here for those who need it.  Hope it helps.
    http://instrumenti-meliora.blogspot.com/2014/04/create-new-text-file-in-utf-8-format-by.html

    You've made a procedure?
    Are you sure you didn't :
    Didn't what?
    https://www.google.com/#q=change+notepad+default+encoding
    Well, I'm not sure what you want me to see, but your search keywords do
    NOT make sense.  You do note change *Notepad* default encoding.  What you can change is a
    TEXT file's default encoding.
    Well, of course, if you have access to Notepad source code and you're able to change it and re-compile again, then you could really say you change Notepad's "default encoding", which I suppose would mean "default encoding every time we save".
    Why wouldn't you just provide a link (or some attribution) to the top result
    http://answers.microsoft.com/en-us/windows/forum/windows_7-windows_programs/default-utf-8-encoding-for-new-notepad-documents/525f0ae7-121e-4eac-a6c2-cfe6b498712c
    or a link to watch this done on youtube?
    http://www.youtube.com/watch?v=GnL6smxQE9k
    The title of that forum post and Youtube video is a non-sense.  New
    "Notepad" document?  Come on!  That's apparently how a newbie think what it is and it's very likely he has not a clue what it is and what he is doing.  And what if I don't use Notepad to create such file?  If I
    use UltraEdit, then mine should be "UltraEdit" document and that should be different from Notepad document, correct? LOL
    The fact that you're able to find this video would also mean you're thinking like him in that the file is really called Notepad document LOL
    For your information, that's called a text file (or document if you prefer this prettier term).  It's also called plain text file.
    Now, let's see the content of both links:
    First of all, why did they tell people to create a new text file somewhere and then
    COPY it to template folder?  That's really so dumb
    LOL  Isn't it more intelligent to create such file directly INSIDE the folder?
    Secondly, their procedures are not foolproof.  What if the Windows directory is not c:\windows?  They should tell people to open %Systemroot%\ShellNew instead.  I suppose they don't even know how this folder is called because
    nowhere is the term "template folder" ever mentioned.
    Thirdly, what if that folder doesn't work for unknown reason (which might happen in XP)?  Did they give any hint to a "failover" folder?  No, they didn't.  But I do in my procedure.
    Fourthly, they are saying as if the file name has to be "TXTUTF-8.txt", but actually we can call it whatever we like.  But smart people would have figured this out at the end.
    5 (I'd stop saying fifthly and so on LOL) I'm not sure it's necessary (or recommended) to change "fSavePageSettings" & "fSaveWindowPositions" DWORD values for Notepad as "advised" in that answer.
    As a side-note, I don't know what
    http://www.pc1news.com/saving-changes-to-notepad-configuration-1216.html is supposed to give but when I open this, I got some uTorrent warning.  Really seems like some malware webpage which tries to deceive people!
    I actually searched how a (generic) new file is created and started from there.
    So, maybe next time when you want to criticize or discredit somebody else, try to be more expert first? ;)

  • How to creat a text file

    hello everybody
    I need your help guys in some java issue
    "surprise"
    how can I create a text file in java
    I mean I wanna check if the file is there and if its not I create it
    thanks

    > mkdirs() only creates the parent directory structure
    (may be needed as well).
    Which is what I assumed at first, based on his report of an error message. However, now I'm not so sure, based on the OP's lack of detail. I can't tell if s/he's just not handling the exception (throws or try/catch), or if s/he is actually getting a "The system cannot find the path specified" message when attempting to create a file for which the appropriate directory does not exist (as is possible with createNewFile()).
    It remains a mystery. :o)
    ~

  • How can FMS create a text file and write data into it in the Server application folders?

    Recently, I writed a programe about creating a text file and writing data into it in the server application folder. My code is as following:
               var fileObj = new File("/MyApp/test.txt");
               if( fileObj !=  null)
                      if(fileObj.open( "text", "append"))
                            fileObj.write( "                                                      ———— Chat Info Backup ————\r\n" );
                            fileObj.close( );
                            trace("Chat info backup document :" +  fileObj.name + " has been created successfully!");    
    But when I run it, FMS throw the error as following: File operation open failed  ;  TypeError: fileObj has no properties.
    Can you help me ? Thanks in advance.
    Supplement: The text file named test.txt doesn't exist before create the fileObj, an instance of File Class.

    Is MyApp the name of the application directory, or is it a child of the application directory? If myApp is the app name, just use test.txt as the path flag in the file constructor.

  • Creating a text file using pl/sql

    how can one create a text file using pl/sql?
    Say for example abcd.txt in the d: drive
    (d:\abcd.txt)
    on a windows nt server

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by bhrigu nagal ([email protected]):
    thanks for your replies
    I had already set the utl_file_dir parameter
    I tried the utl package and wrote the following code but got some errors
    declare
    filehandler UTL_FILE.FILE_TYPE;
    begin
    filehandler:=UTL_FILE.fopen('d:/intel/','myfile.txt','w');
    utl_file.put_line(filehandler,'look masjdfgsd\n');
    utl_file.fclose(filehandler);
    exception when utl_file.invalid_path then
    raise_application_error(-20023,'bhrigu ,chk the path');
    end;
    the errors
    ERROR at line 1:
    ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "SYS.UTL_FILE", line 101
    ORA-06512: at "SYS.UTL_FILE", line 157
    ORA-06512: at line 4
    if u know what this is please tell me
    thanks bhrigu
    <HR></BLOCKQUOTE>
    U need :
    1) To have UTL_FILE_DIR param in the init file of the instance with the same directory (don't forget to stop and restart the base)
    2) Handled the exceptions listed in the utl_file package (Oracle_home\rdbms\admin\utlfile.sql) in your source.
    3) Turn set serveroutput on in SQL*Plus.
    Run your procedure and see the error message to debug.
    Good luck
    null

  • Not able to create a text file in Client Machine using Forms 10g

    Hi - I'm mot able to create a text file in Client Machine using Forms 10g. I'm getting error when system executes the bolded line.(i.e. CLIENT_TEXT_IO.FOPEN). During run-time system is throwing "ORA-06508: PL/SQL: could not find program unit being called".
    I had attached webutil.pll in the form.
    Please advise me.
    DECLARE
    l_Temp CLIENT_TEXT_IO.FILE_TYPE;
    LC$Name Varchar2(100) ;
    LC$Fic Varchar2(100) ;
    LN$Lines Pls_integer := 0 ;
    LC$Line Varchar2(4000) ;
    Cursor C_CUR Is
    Select * From TEST_TEXTIO where rownum <= 50;
    BEGIN
    LC$Name := 'tmp_file.txt' ;
    LC$Fic := 'c:\temp\tmp_file.txt';
    Begin
    l_temp := CLIENT_TEXT_IO.FOPEN( 'C:\temp\tmp_file.txt', 'W');
    Exception
         when others then
         message( 'OPEN FILE ERROR ' || LC$Fic ||sqlerrm );
         display_error;
         raise form_trigger_failure;
    End ;
    -- Write the lines --
    For Cur In C_CUR Loop
         LC$Line := Cur.CODE || ' -> ' || Cur.COL1 || ',' || Cur.COL2 || ',' || Cur.Col3 ;
         CLIENT_TEXT_IO.PUT_LINE( LF$File, LC$Line ) ;      
         LN$Lines := C_CUR%ROWCOUNT ;
    End loop ;
    -- Close the file --
    CLIENT_TEXT_IO.FCLOSE( LF$File ) ;
    Exception
         When others Then
    message('err='||sqlerrm);message(' ');
    display_error;
    CLIENT_TEXT_IO.FCLOSE( LF$File ) ;      
         Raise ;
    END;
    Thanks.
    Arun

    Hi ,
    i have one Question though its not related to thos question if some could help me it will be really helpful,
    i have created one program to import and export excel to forms vice versa, if the form is attached with webutil its working fine am using ole2.but i have a new idea if i add this program in menu, it can be used for all the forms attched to that menu, i made program also, but problem am facing right now is if the form is not attched with webutil it will not work so is there possiblity to share my webutil from one form to another form ,so i will keep one form as a interface form in that webutil will be attched ,i can share that webutil to all other forms so that all the forms no need to attach webutil again
    if its possible means please suggest some ideas

  • How to create a text file or XML file  and add content through  code into it...

    Hi Everyone,
    How to create a text file and add content through the code to the text file eform javascript ......orelse can we create a text file in life cycle designer...
    Else say how to create a new XML file through the code and how some content like Example "Hello World".

    You can create a text file as a file attachment (data object) using the doc.createDataObject and doc.setDataObjectContents:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.450.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.528.html
    You can then export the file with the doc.exportDataObject method:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.463.html
    This won't work with Reader if it hasn't been given the file attachment usage right with LiveCycle Reader Extensions.

  • I was given an assingment, but have no idea where to begin. The assingment is to create a text file using notepad with all of my digital inputs and some how make those imputs show up on my digital indicators on my control pannel

    I was given an assingment, but have no idea where to begin. The assingment is to create a text file using notepad with all of my digital inputs and some how make those imputs show up on my digital indicators on my control pannel.
    When it was explained to me it didn't sound to hard of a task, I have no LabVIEW experience and the tutortial sucks.

    StevenD: FYI, I did NOT give you the one star rating. I would never do that!
    StevenD wrote:
    Ow. Someone is grumpy today.
    Well, this is an assignment, so it is probably homework.
    Why else would anyone give HIM such an assigment, after all he has no LabVIEW experience and the tutorials are too hard for him?
    This would make no sense unless all of it was just covered in class!
    This is not a free homework service with instant gratification.
    OK! Let's do it step by step. I assume you already have a VI with the digital indicators.
    "...but have no idea where to begin".
    open notepad.
    decide on a format, possibly one line per indicator.
    type the document.
    close notepad.
    open LabVIEW.
    Open the existing VI with all the indicators.
    (are you still following?)
    look at the diagram.
    Who made the program?
    Does the code make sense so far?
    Is it a statemachine or just a bunch of crisscrossed wires?
    Where do you want to add the file read?
    How should the file be read (after pressing a read button, at the start of the program ,etc.)
    See how far you get!
    Message Edited by altenbach on 06-24-2008 11:23 AM
    LabVIEW Champion . Do more with less code and in less time .

  • How to create a text file from jsp?

    In JSP, what is the command to create a text file and dump a variable in it?

    You mean StringBuffer?

  • How can I add a "Create New Text File" contextual menu?

    Hi,
    I'd like to add a "Create New Text File" contextual item. I found the "new text file" action in Automator, but I don't really know where to go from there... I want it to work on the desktop and in finder...
    Thanks

    See:
    Mac OS X Automation,
    Automated Workflow Tips,
    Introduction to Automator tutorial, and
    a four-parter on Automation in Snow Leopard by Sal Saghoian:
    Snow Leopard Services,
    Services for iPhoto,
    Safari and WebKit integration, and
    Installing and using services.
    Finally, 
    Developing AppleScript Applications and
    Apple's Automator Developer Documentation

  • Creating a text file

    hi
    can anyone tell me how to create a number of text file using a different variable in java.the exact definition is like this "different variables are stored in a text file and each time it has to open this file, take these as their file name and create a text file"

    new File(thevariable)

  • How to Create a text file through Portal

    Hi,
    Is there any way to create a text file(e.g Excel file) through Portal? Thanks.
    Sumita

    I have a way to do this in VBScript, I don't know if it will work with the portal but the steps are simple. If you can create a text file within portal, try to create it as an html table:
    <table>
    <tr>
    <td>Column Header 1</td>
    <td>Column Header 2</td>
    </tr>
    <tr>
    <td>Value 1</td>
    <td>Value 2</td>
    </tr>
    <tr>
    </tr>
    </table>
    When you create this file save it with XLS extension instead of TXT, create a link to it and voila! it will load Excel and you will have your data well formatted. I found this method rather better than save the file as a CSV. You can also include any html attribute inside the <TD> or <TR> like background color and font type, Excel will keep those attributes.
    I hope this will help
    Arturo

  • How to create a text file with data.

    Hi,
    I am writing java code for testing an application, some times test can failed in some cases, I want to display an error message in text file. To that I written the code as like,
    BufferedWriter bout;
    bout =new BufferedWriter(new FileWriter("test.txt"));
    String str=”Your input data is not match with pattern”
    bout.write(str);but here it is creating a text file “ test” without any data in it.
    Can any body help that to execute the program properly
    Regards
    Buntty

    sabre150 wrote:
    JoachimSauer wrote:
    You didn't close your BufferedWriter. Since it's buffered it probably didn't write anything to the underlying file.
    Generally you must close every Writer/OutputStream that you no longer use or it won't be written reliably.It's not quite as simple as that. If you have a chain of Writers / OutputStreams then you only have to close() the outer most one since each is responsible for closing any Writer/OutputStream that it wraps. If you do decide to close them individually (a bad idea but people do do it) then you MUST close them starting from the outer most one and working to the most inner one or you will not guarantee to flush any buffered content.Of course. I might have used a misleading phrasing here. What I meant is "Every time you are done with a Writer, you must close it" and not "You must close *every* Writer that you used". Thanks for the clarification.

  • Writing a file to an Oracle Directory

    Hello,
    I'd like to use a database trigger or PL/SQL to write a text file to to a directory on my database server. Is that possible? I know I could write a daemon that runs on the OS, but I'd lie to run it from the database itself.

    OK, figured it out. This was helpful: http://www.adp-gmbh.ch/ora/sql/create_directory.html

Maybe you are looking for