How to create and write in a file

Hello Gurus,
I am creating a file based on the date and time and writing into that. But, I am still getting exception error and all. Kindly, please let me know.
thanks for all the help...j
Error:-
C:\Usage\JavaFiles>java filename "abc"
Exception in thread "main" java.io.FileNotFoundException:Detail09-2003-
03:28:04.doc (The system cannot find the file specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:176)
at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
at TowerDetail.main(TowerDetail.java:30)
Code sample:-
import java.io.*;
import java.util.*;
import java.lang.*;
import java.sql.*;
import java.text.*;
public class TowerDetail{
public static void main (String[] args) throws IOException{
String userName = "user";
String passwd = "pwd";
String con_db = "jdbc:odbc:datasource";
String ssn = args[0];
Vector results = new Vector();
Connection con = null;
CallableStatement cstmt = null;
java.util.TimeZone tz = java.util.TimeZone.getTimeZone("EST");
java.util.Date now = new java.util.Date();
DateFormat df = new SimpleDateFormat("MM-dd-yyyy-hh:mm:ss");
df.setTimeZone(tz);
String result = df.format(now);
String fileName = "Detail"+result+".doc";
File inputFile = new File(fileName);
FileOutputStream fos = new FileOutputStream(inputFile);
PrintWriter pw = new PrintWriter(fos);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch (Exception e) {
System.out.println("JDBC Error: "+e.getMessage());
return;
try{
con = DriverManager.getConnection(con_db, userName, passwd);
cstmt = con.prepareCall("{call dbo.sp_usage_detail(?)}");
cstmt.setString(1, ssn.trim());
ResultSet rs = cstmt.executeQuery();
pw.println("Report "+result);
pw.println("------------------------------------------------------------------------------------
while(rs.next()){
.... write in the file...
pw.println("------------------------------------------------------------------------------------
pw.close();
System.out.println("Your file Detail"+result+".doc is ready!!!");
cstmt.close();
con.close();
}catch(SQLException ex){
System.out.println("SQLException: ");
System.out.println(ex.getMessage());
}catch(NullPointerException e){
System.out.println("Null Pointer Exception: ");
System.out.println(e.getMessage());

Now, I got out of the command prompt and reentered. I didn't set any classpath or anything. I have created a subdir \archive in the C:\ and writing an output file [DetailTower.....doc")into that.
The DetailTower.class is in C:\Detail\ProjectClass dirctory.
Now at,
C:\Detail\ProjectClass\java -classpath . DetailTower "abc"
I am getting this error:-
C:\Detail\ProjectClass>java -classpath . DetailTower "999999"
Exception in thread "main" java.io.FileNotFoundException: c:\archive\DetailTower09-10-2003-06:23:40.doc (The system cannot find the file specified)at java.io.FileOutputStream.open(Native Method)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:176)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
        at Detail.main(DetailTower.java:32)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • How to create and manage the log file

    Hi,
    I want to trace and debug the program process.
    I write the code for creating log file and debugging the process.
    But i am not able get the result.
    please help me how to create and manage the log file.
    Here i post sample program
    package Src;
    import java.io.*;
    import org.apache.log4j.*;
    import java.util.logging.FileHandler;
    public class Mylog
         private static final Logger log = Logger.getLogger("Mylog.class");
         public static void main(String[] args) throws Exception {
         try {
           // Create an appending file handler
            boolean append = true;
            FileHandler handler = new FileHandler("debug.log", append);
            // Add to the desired logger
            Logger logger = Logger.getLogger("com.mycompany");
            System.out.println("after creating log file");     
              catch (IOException e)
                   System.out.println("Sys Err");
            }Please give the your valuable suggesstion... !
    Thanks
    MerlinRoshina

    Just i need to write a single line in log file.

  • How to create and edit a .ini file using java

    Hi All...
    Pls help me in creating and editing an .ini file using java...
    thanks in advance
    Regards,
    sathya

    Let's assume the ini file is a mapping type storage (key=value) so lets use Properties object. (works with java 1.4 & up)
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Properties;
    public class Test {
         private static Properties props;
         public static void main(String[] args) throws IOException {
              File file = new File("test.ini");//This is out ini file
              props = new Properties();//Create the properties object
              read(file);//Read the ini file
              //Once we've populated the Properties object. set/add a property using the setProperty() method.
              props.setProperty("testing", "value");
              write(file);//Write to ini file
         public static void read(File file) throws IOException {
              FileInputStream fis = new FileInputStream(file);//Create a FileInputStream
              props.load(fis);//load the ini to the Properties file
              fis.close();//close
         public static void write(File file) throws IOException {
              FileOutputStream fos = new FileOutputStream(file);//Create a FileOutputStream
              props.store(fos, "");//write the Properties object values to our ini file
              fos.close();//close
    }

  • How to create and write a BLOB using ImmediateAccess

    Hi there,
    I'd like to write a BLOB using ScrollableRowSetAccess an ImmediateAccess and thereby want to avoid the use of any SQL-statements.
    The problem is that I can't write to an empty BLOB, so that I have to create a dummy-Blob using BLOBDomain and overwrite it afterwards (see code below).
    It should be possible to avoid the creation of a dummy-BLOB but I don't know how. Could you please send me a corrected version of my code?
    Thanks in advance
    write File with filename to the column with index col /(or the column with name colname, if specified) of the table that is specified by ResultSetInfo rsi
    public static void writeFileToBlob(int col, String colname, ResultSetInfo rsi, String filename, SessionInfo _sessionInfo)
    FileInputStream fin;
    Object obj;
    ScrollableRowsetAccess srsa= _rsi.getRowsetAccess();
    ImmediateAccess ia;
    byte []mybytes;
    BlobDomain
    BLOB blob;
    OutputStream out;
    byte []myBuffer;
    int bytesRead=0;
    try{
    //open file
    fin = new FileInputStream(_filename);
    //lock Row
    srsa.lockRow();
    if (_colname==null)
    ia = (ImmediateAccess)srsa.getColumnItem(_col);
    else
    ia = (ImmediateAccess)srsa.getColumnItem(_colname);
    obj= ia.getValueAsObject();
    //insert a dummy-BLOB of size 1-byte
    mybytes= new byte[1];
    blobDom= new BlobDomain();
    blobDom.setBytes(mybytes); //ein Byte in den BLOB schreiben
    ia.setValue(blobDom); //Wert in Zeile einf|gen
    //commit Data
    _sessionInfo.getApplicationModule().getTransaction().commit();
    //access previously created dummy-Blob
    srsa.lockRow();
    if (_colname==null)
    ia = (ImmediateAccess)srsa.getColumnItem(_col);
    else
    ia = (ImmediateAccess)srsa.getColumnItem(_colname);
    obj= ia.getValueAsObject();
    //assign the BLOB
    blob= (BLOB) obj;
    //open BLOB for writing
    out= blob.getBinaryOutputStream();
    myBuffer= new byte[10*1024];
    //read file and write the BLOB
    while ((bytesRead= fin.read(myBuffer)) !=-1)
    out.write(myBuffer, 0, bytesRead);
    out.flush();
    out.close();
    fin.close();
    ia.setValue(blob);
    //commmit data
    _sessionInfo.getApplicationModule().getTransaction().commit();
    }catch(Exception e){System.out.println("writeblob:"+e);}
    null

    Here are the issues with your usage of BlobDomain:
    1. Streaming support is not implemented in 3.2 version of BlobDomain. It'll be implemented in our next release.
    2. Your casting of object returned from getColumnItem is illegal as the objects will be of type BlobDomain and not BLOB.
    3. When you create an empty BlobDomain you're in-effect meaning to call the empty_blob() method on the sql-row to create a empty blob locator.
    4. You need to use getBytes(), setBytes() to read data out/set data into a blob/clob domain object in JDev 3.2
    5. Casting/using oracle.sql.BLOB may lead to non-portable code (you're binding to the jdbc objects which may not be available in all tiers of deployment).
    Here's the pseudocode you could use for new blobs.
    1. create a new instance of BlobDomain()
    2. setBytes() with actual data read from a stream. (Yes this may not work with real large blobs but we've tested blobs ~2MB in size and for larger needs, we're implementing the streaming support scheduled for our next release).
    3. set the domain object into an attribute.
    4. post/commit your data.
    null

  • Open/Create and write to mulitple files

    I am trying to do high speed data acquisition, and save data to file.  I will acquire a large number of data, so saving to just one file would result in my file blowing up in size.  Hence I would like to save my data to mulitple files.  I am trying to figure out how to open multiple files, then chose which file to write to.  My approach is to open/create multiple files and save their refnum in an array.  Then i would like to pick which file to write from this array.  I have attached my VI, whatever I have so far.  I seem to get errors like, "Duplicate path" or " An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @."  How would I get started with this problem?
    Solved!
    Go to Solution.
    Attachments:
    Create & Save to Mulitples Files.vi ‏24 KB

    Figured it out...
    sorry for the trouble!

  • How to create and handle a text file in CVI

    Is there any way to create and handle (like...open,write,read,truncate,close)  the .txt file in CVI?

    Sure. CVI is a regular C compiler and hence you can use all ANSI C functions. In addition you can use the File I/O functions from the utility library.

  • How to create and use library JAR files with command-line tools?

    Development Tools -> General Questions:
    I am trying to figure out how to put utility classes into JAR files and then compile and run applications against those JAR files using the command-line javac, jar, and java tools. I am using jdk1.7.0_17 on Debian GNU/Linux 6.0.7.
    I have posted a simple example with one utility class, one console application class, and a Makefile:
    http://holgerdanske.com/users/dpchrist/java/examples/jar-20130520-2134.tar.gz
    Here is a console session:
    2013-05-20 21:39:01 dpchrist@desktop ~/sandbox/java/jar
    $ cat src/com/example/util/Hello.java
    package com.example.util;
    public class Hello {
        public static void hello(String arg) {
         System.out.println("hello, " + arg);
    2013-05-20 21:39:12 dpchrist@desktop ~/sandbox/java/jar
    $ cat src/com/example/hello/HelloConsole.java
    package com.example.hello;
    import static com.example.util.Hello.hello;
    public class HelloConsole {
        public static void main(String [] args) {
         hello("world!");
    2013-05-20 21:39:21 dpchrist@desktop ~/sandbox/java/jar
    $ make
    rm -f hello
    find . -name '*.class' -delete
    javac src/com/example/util/Hello.java
    javac -cp src src/com/example/hello/HelloConsole.java
    echo "java -cp src com.example.hello.HelloConsole" > hello
    chmod +x hello
    2013-05-20 21:39:28 dpchrist@desktop ~/sandbox/java/jar
    $ ./hello
    hello, world!I believe I am looking for:
    1. Command-line invocation of "jar" to put the utility class bytecode file (Hello.class) into a JAR?
    2. Command-line invocation of "javac" to compile the application (HelloConsole.java) against the JAR file?
    3. Command-line invocation of "java" to run the application (HelloConsole.class) against the JAR file?
    I already know how t compile the utility class file.
    Any suggestions?
    TIA,
    David

    I finally figured it out:
    1. All name spaces must match -- identifiers, packages, file system, JAR contents, etc..
    2. Tools must be invoked from specific working directories with specific option arguments, all according to the project name space.
    My key discovery was that if the code says
    import com.example.util.Hello;then the JAR must contain
    com/example/util/Hello.classand I must invoke the compiler and interpreter with an -classpath argument that is the full path to the JAR file
    -classpath ext/com/example/util.jarThe code is here:
    http://holgerdanske.com/users/dpchrist/java/examples/jar-20130525-1301.tar.gz
    Here is a console session that demonstrates building and running the code two ways:
    1. Compiling the utility class into bytecode, compiling the application class against the utility bytecode, and running the application bytecode against the utility bytecode.
    2. Putting the (previously compiled) utility bytecode into a JAR and running the application bytecode against the JAR. (Note that recompiling the application against the JAR was unnecessary.)
    (If you don't know Make, understand that the working directory is reset to the initial working directory prior to each and every command issued by Make):
    2013-05-25 14:02:47 dpchrist@desktop ~/sandbox/java/jar
    $ cat apps/com/example/hello/Console.java
    package com.example.hello;
    import com.example.util.Hello;
    public class Console {
        public static void main(String [] args) {
         Hello.hello("world!");
    2013-05-25 14:02:55 dpchrist@desktop ~/sandbox/java/jar
    $ cat libs/com/example/util/Hello.java
    package com.example.util;
    public class Hello {
        public static void hello(String arg) {
         System.out.println("hello, " + arg);
    2013-05-25 14:03:03 dpchrist@desktop ~/sandbox/java/jar
    $ make
    rm -rf bin ext obj
    mkdir obj
    cd libs; javac -d ../obj com/example/util/Hello.java
    mkdir bin
    cd apps; javac -d ../bin -cp ../obj com/example/hello/Console.java
    cd bin; java -cp .:../obj com.example.hello.Console
    hello, world!
    mkdir -p ext/com/example
    cd obj; jar cvf ../ext/com/example/util.jar com/example/util/Hello.class
    added manifest
    adding: com/example/util/Hello.class(in = 566) (out= 357)(deflated 36%)
    cd bin; java -cp .:../ext/com/example/util.jar com.example.hello.Console
    hello, world!
    2013-05-25 14:03:11 dpchrist@desktop ~/sandbox/java/jar
    $ tree -I CVS .
    |-- Makefile
    |-- apps
    |   `-- com
    |       `-- example
    |           `-- hello
    |               `-- Console.java
    |-- bin
    |   `-- com
    |       `-- example
    |           `-- hello
    |               `-- Console.class
    |-- ext
    |   `-- com
    |       `-- example
    |           `-- util.jar
    |-- libs
    |   `-- com
    |       `-- example
    |           `-- util
    |               `-- Hello.java
    `-- obj
        `-- com
            `-- example
                `-- util
                    `-- Hello.class
    19 directories, 6 filesHTH,
    David

  • How to read and write from XL file

    HI ,
    I wanted to read a data from XL file and write a data in XL file by generating a report .Can any body help me out.Many examples are available on discussion forums but when I try to save and run those Vi .I am not able to run Showing error .Please tell what is going wrong as I m having latest labview 8.6 .
    Regards
    Sharmila.karale

    Hi Adnan,
    Here are the examples of Vi which I have downloaded from the forum for my reference
    Regards
    Sharmila.Krale
    Attachments:
    SAVE TO EXCEL.llb ‏128 KB
    excel.llb ‏1618 KB

  • How to create and attach a pdf file to an email

    I am looking into the feasibility of using email system to send indentical notices along with data attachments to hundreds of companies simultaneously. Each data attachment is corresponding to its own company email.
    Please advise how can I create this file. What tool(s) do I need?
    Thanks in advance for your assistance.
    ML

    user627993,
    First thing is that this forum is for OTN community feedback and suggestions as the forum header says. Second, you have not provided any background of scenario like platform, tools, business case etc, so its impossible to suggest where to post.
    You can go to forum home page
    http://forums.oracle.com/forums/categoryHome.jspa?categoryID=84 and check which one is suitable for your case.
    --Shiv                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to create and modify an XML file from an Oracle Form

    I would like to build an Oracle Form to maintain a small XML file in the file system (i.e. Not in Oracle database but in the operating system).
    I would like the Form to display existing values from the XML file and the user can update and save content back to the XML file.
    Can any one tell me how this can be done? Thanks.

    Does Forms 9i provide any XML Parser Functions?
    Can I insert the XML file into a table column by inserting XML using the XSU Front End rather than using TEXT_IO to maintain the XML file directly?
    Can I use XSU PL/SQL API in Forms to retrieve and modify XML values?
    Any help is appreciated.

  • How to create a write operation in file adapter dynamically in to a folder.

    Hi all
    i want to explain my scenario...
    i am giving input to file adpter which is having read operation,and i am giving that input to an human work flow.i had two operations reject and resubmit in my task flow...i am editing the task with some changes...and resubmiting the task from the oracle bpm worklist.......now how can i give that task to again my input folder.....
    and another question is,
    if i am using three file adpters with 3 differnt folder structure having read operations.and i am giving only one file to one file adapter.and i am giving it to human work flow and i am editing it and i have to resubmit the file to the input folder.....so i i have to give back to input folder dynamically(with out hard coding the folder structure).....How can i give ?????
    so any one can help me....please...
    Thanks in advance...
    varma.

    ya...its gd....but i had a problem in my scenariou....
    i used this concept as a error handling frame work....that means
    i had so many composites which take purchase order as its input from a file adapter........if the input order differs from my xsd,i populated that input as a error file in another folder using some fault handlers... and i am giving that folder to human work flow and i a m editing that task and i am resubmiting it...so that it should go to the input folder of my composites as a input again...so how to differ ,for which composite i have to give as this task as input again.....dynamically it should vary in ...........
    please help me....
    thanks in advance....
    varma

  • How to create and deploy a war file on wls using the console

              my question is how to deploy the simpleSession.jsp example in the weblogic/samples/examples/jsp/
              dir examples as a war file on wls cluster what are the steps to do so.. thanks
              in advance
              

    [att1.html]
              

  • How to read and write a data from extrenal file

    Hi..
    How to read and write a data from extrenal file using Pl/sql?
    Is it possible from Dyanamic Sql or any other way?
    Reagards
    Raju

    utl_file
    Re: How to Create text(dat) file.
    Message was edited by:
    jeneesh

  • How to read the and Write the PDF file give me the solution

    Hi all,
    How to read the and Write the PDF file give me the solution
    My coding is
    import java.io.File;
    import com.asprise.util.pdf.PDFImageWriter;
    import com.asprise.util.pdf.PDFReader;
    import java.io.*;
    import java.io.FileOutputStream;
    public class example {
    // public example() {
         public static void main(String a[])
              try
              PDFReader reader = new PDFReader(new File("C:\\AsprisePDF-DevGuide.pdf"));
                   reader.open(); // open the file.
                   int pages = reader.getNumberOfPages();
                   for(int i=0; i < pages; i++) {
                   String text = reader.extractTextFromPage(i);
                   System.out.println("Page " + i + ": " + text);
    // perform other operations on pages.
    PDFImageWriter writer = new PDFImageWriter(new FileOutputStream("c:\\new11.pdf"));
                   writer.open();
                   writer.addImage("C:\\sam.doc");
                   writer.close();
                   System.out.println("DONE.");
    reader.close();
              catch(Exception e){System.out.println("error:"+e);
              e.printStackTrace();
    I get the pdf content then it returns the string value but ther is no option to write the string to PDF, and we only add a image file to PDF,but i want to know how to wrote the string value to PDF file,
    Please give response immtly
    i am waiting for your reply.
    thanks,
    Suresh.G

    I have some question flow
    How library to use this code.
    I try runing but have not libary.
    Please send me it'library
    Thank you very much!

  • How to read and write a string into a txt.file

    Hi, I am now using BEA Workshop for Weblogic Platform version10. I am using J2EE is my programming language. The problem I encounter is as the above title; how to read and write a string into a txt.file with a specific root directory? Do you have any sample codes to reference?
    I hope someone can answer my question as soon as possible
    Thank you very much.

    Accessing the file system directly from a web app is a bad idea for several reasons. See http://weblogs.java.net/blog/simongbrown/archive/2003/10/file_access_in.html for a great discussion of the topic.
    On Weblogic there seems to be two ways to access files. First, use a File T3 connector from the console. Second, use java.net.URL with the file: protocol. The T3File object has been deprecated and suggests:
    Deprecated in WebLogic Server 6.1. Use java.net.URL.openConnection() instead.
    Edited by: m0smith on Mar 12, 2008 5:18 PM

Maybe you are looking for

  • How to drop user giving error ORA-03113

    hello, I am trying to drop user as follows SQL> drop user jbponm_trf cascade; drop user jbponm_trf cascade ERROR at line 1: ORA-03113: end-of-file on communication channel SQL> pls suggest me how to drop user.

  • Error when posting Trip in FI-TV

    hi there. when we try and post a trip in Travel Management, the system generates the following error: Entry not found in table T706U. Argument: 54P KE 2 J 20080724. This may be an integration issue with Funds Management. any ideas? thanks.

  • What is changedocument_read_headers.....

    dear friends..,,   what is changedocument_read_headrs and changedocument_read_position, in respect to data accessing from cdpos and cdhdr cluster tables...what will be its syntax any code or article will be great help... thanking you,,,,,

  • Can I sell my copy without problems?

    I bought a new Family Pack OSX Leopard when it first came out. I have since bought Snow Leopard, and the original is now redundant. If I sell (or even give away) my original retail pack of Leopard, will the new owner be able to install it without pro

  • When i open new page, it has the outline of a selection i made a few pages ago

    this is what i see when i open a new page. it is part of a selection i made a few pages back. i can delete it and use another, blank layer, but when i "fill" the layer, this is what it is filled with. relatively familiar with photoshop basics, have n