How to create a CSV file in java

how to create a CSV file in java

this is the code that I have used in a hp project:
private static final String DELIMIT = ",";
StringBuffer buf = new StringBuffer();
public void addString(String str){
buf.append(toEscapedStringLiteral(str.replaceAll(" ","").trim())).append(DELIMIT);
public void sendFile( String strData ,
                            String strTitle,
                            String strContType,
                            HttpServletResponse res ) throws IOException {
          byte[] _filedata=strData.getBytes();
          res.setContentType( strContType );
          res.setHeader( "Content-Disposition", "attachment;filename="+ strTitle );     
                 DataOutputStream out = new DataOutputStream( res.getOutputStream() );
          out.write( _filedata, 0, _filedata.length );
          out.close();
public void addStringWhithReturn(String str){
          buf.append(toEscapedStringLiteral(str.replaceAll(" ","").trim()));
          buf.append( "\n" );
private String toEscapedStringLiteral( String charSeq ) {
          if ( null == charSeq ) {
               charSeq = "";
          return "\"" + charSeq + "\"";
....hope its help
kou

Similar Messages

  • How to create a Batch file for java application  ?

    HI,
    How to create a Batch file for java application ?
    And whats the use of creating batch file ?
    Thanks in advance

    [http://static.springsource.org/spring-batch/]
    Assuming you want to develop a batch application rather than actually just create a .bat file ..

  • HOw to create a Batch file for java application and whats the use of this ?

    HI,
    How to create a Batch file for java application ?
    And whats the use of creating batch file ?
    Thanks in advance

    First of all, you're OT.
    Second, you can find this everywhere in the net.
    If you got a manifest declaring main class (an classpath if needed), just create a file named whatever.bat, within same directory of jar file, containing:
    javaw -jar ./WhateverTheNameOfYourJarIs.jar %*By the way, assuming a Windows OS, you can just double click the jar file (no batch is needed).
    Otherwise use:
    javaw -cp listOfJarsAndDirectoriesSeparedBySemiColon country/company/application/package/className %*Where 'country/company/application/package/' just stands for a package path using '/' as separator instead of '.'
    Don't specify the .class extension.
    Javaw only works on Windows (you asked for batch, I assumed .BAT, no .sh), in Linux please use java.exe (path may be needed, Windows doesn't need it 'cause java's executables are copied to system32 folder in order to be always available, see PATH environment variable if you don't know what I'm talking about) and use ':' as classpath (cp) separator.
    The '%***' tail is there in order to pass all parameters, it only works on Windows, refer to your shell docs for other OSs (something like $* may work).
    This way you have a command you can call to launch your code (instead of opening NetBeans just to see your app working). You could schedule tasks on it or just call it in any command prompt (hope you know what it is 'cause there have been people in this very same forum with no clue about it, if not just hold the 'Windows button' and press 'R', then type 'cmd' and run it).
    Finally add dukes and give 'hem away.
    Bye.

  • How to create the exe file for java project.

    How to create the exe file for java project.
    am done the project in java swing , i like to create the project in exe format, so any one help for me,
    send the procedure for that.
    thanking u.

    How to create the exe file for java project.Have you ever heard of google? I pasted your exact "question" into a google search:
    http://www.google.com/search?q=How+to+create+the+exe+file+for+java+project.
    and got several useful links.
    Better search terms might yield even better results.
    Sheesh.

  • How to create a csv file with NCS attributes?

    Hi
    i installed Cisco Prime NCS and trying to perform bulk update of device credentials with csv file.
    How to create a csv file with all required attributes?
    This is part of NCS online help talking about this topic:
    Bulk Update Devices—To update the device credentials in a bulk, select Bulk Update Devices from the Select a command drop-down list. The Bulk Update Devices page appears.You can choose a CSV file.
    Note        The CSV file contains a list of devices to be updated, one device per line. Each line is a comma separated list of device attributes. The first line describes the attributes included. The IP address attribute is mandatory.
    Bellow is test csv file i created but does not work:
    10.64.160.31,v2c,2,10,snmpcomm,ssh,zeus,password,password,enablepwd,enablepwd,60
    10.64.160.31,v2c,2,10,snmpcomm,ssh,zeus,password,password,enablepwd,enablepwd,60
    The error i am getting while importing this file:
    Missing mandatory field [ip_address] on header line:10.64.160.31,v2c,2,10,snmpcomm,ssh,zeus,password,password,enablepwd,enablepwd,60
    Assistance appreciated.

    It looks like the IP address field is incorrectly set.,
    It should be as follows
    {Device IP},{Device Subnet Mask}, etc etc
    so a practical example of the aboove could be (i dont know if this is completely correct after the IP address / Subnet Mask)
    10.64.160.31,255.255.255.0,v2c,2,10,snmpcomm,ssh,zeus,password,password,enablepwd,enablepwd,60
    below is a link to the documentation
    http://www.cisco.com/en/US/docs/wireless/ncs/1.0/configuration/guide/ctrlcfg.html#wp1840245
    HTH
    Darren

  • How to create the exe files for java application

    How to create the exe file for java application?
    got any software to do that?
    Thanks

    In terms of converting java applications into exe files, there are 3 schools of thought:
    1) Instead of converting it to an exe, convert it to a jar file. Jar files are more portable than exe files because they can be double-clicked on any operating system. The caveat is that a Java interpreter must be installed on the target computer for the double-clicking to work.
    http://developer.java.sun.com/developer/Books/javaprogramming/JAR/
    2) Create an exe launcher that, when double-clicked, attempts to find a Java interpreter on the local computer and launches the Java application. The exe file is still double-clickable but whether your java application runs depends on whether a Java interpretor is installed on the target computer.
    http://www.sureshotsoftware.com/exej/
    http://www.objects.com.au/products/jstart/index.jsp
    http://www.duckware.com/products/javatools.html
    http://www.ucware.com/jexec/
    http://www.rolemaker.dk/nonRoleMaker/javalauncher/
    http://www.jelude.cjb.net/
    http://thor.prohosting.com/~dfolly/java/index.html
    3) Create an exe launcher that bundles a Java interpretor. Same as above but when the exe file is double-clicked, it searches for a Java interpreter and if one is not found, it installs one on the target computer. The caveat is that the exe file would have an overhead of 10 MB in size for the interpreter.
    http://www.excelsior-usa.com/jet.html (evaluation version available)
    4) Convert the Java application into a native exe file. The caveat is that if you use Swing for your GUI, it won't be converted. Also this option is still somewhat experimental.
    Can't think of any free options right now.

  • How to create a .CSV file & place it  in Application server

    Hi All,
    I have a requirement like .
    1.Create a .CSV file by using report output data.
    2.The .csv file should be placed in application server.
    When user will execute the report,
    automatically a .csv has to generate and that should be available at application server.
    points will be rewarded.
    Thanks,
    Anil

    Hi,
      Whatever the final output internal table is there  loop that
    DATA : begin of i_final occurs 0,
                  field1(20),
                  field2(20),
                end of i_final.
    DATA : v_filepath (200) TYPE c Value '/data/sapdata/test.csv' .
    DATA : begin of i_file_data occurs 0,
                  Rec(500),
                end of i_file_data.
    LOOP AT i_final.
    CONCATENATE i_final-field1  i_final-field2  INTO i_file_data-rec SEPARATED BY ','.
    APPEND i_file_data.
    CLEAR  i_file_data.
    ENDLOOP.
    OPEN DATASET v_filepath IN OUTPUT  FOR TEXT MODE.
    LOOP AT i_file_data.
      TRANSFER  i_file_data-rec TO  v_filepath.
    ENDLOOP.
    CLOSE v_filepath.
    To check the file goto Tcode->AL11>data/sapdata/test.csv.

  • How to create the setup file in java

    hi
    am new to java...
    is it possible to create setup file in java like in .net..
    if yes how?

    i mean our application can be installed in to any other system..
    using .net we can easily generate setup fileThe other people understood what you meant.
    And they suggested that you use one of the free
    installer generator, such as
    http://www.java-source.net/open-source/installer-generators

  • How to create search index files for Java Pet Store

    Hi All,
    As you may know, the java pet store application uses for the search function a search index object, which itself uses the following files '_36.cfs', 'deletable', 'segments'.
    Now as I want to change the data of the database (delete some pets, and names, etc.), it does not have an effect on the search results. This is because the application uses the search index files and does not use the database for the search query.
    So can anybody help me and tell me how I can create this three files from my *.sql file, so I can search in my own data?
    Thank you very much for your help.
    Regards,
    Wolfgang

    gonso777 wrote:
    Solved:
    I had the same problem. It seems that the installer does not unzip three files where it should.
    With NetBeans (Using File Perspective) or just editing build.xml
    Netbeans: select build.xml/Run Target/Other Targets/unzipindexes: Tough it should work it fails in resolving $javaee.domaindir$ at least in my system, but it does suscessfully create a new directory named ${jee.domaindir} that includes lib/petstore/searchindex and three files: _36.cfs , deletable, segments.
    Copy those three files to your_glasshfish_path/domains/domain1/petstore/searchindex.
    Now you are done. I hope that you had a nice time while waiting two years for it to be answered. How is it that it is not answered anywhere else?
    Regards,
    Ramon Talavera
    www.sciencetechworks.comThanks. I didn't wait 2 years for this, but I just replied on a 2 year old post. I only recently tried the petstore app. I thought I needed to study lucene first to figure things out, it turns out there was an 'internal target' on the build file for this. Thanks a bunch!

  • How to create a movie file of java 3D animation without altering the code?

    Is there a way to create a movie file of a Java 3D animation without altering the source code of the Java 3D animation program???
    Because as what I observed, most of the forum recommends extracting the bufferedimages of the animation. And, then using the bufferedimages to do a movie file. In this way, I will need to add in new code in the animation program in order to extract the bufferedimages.
    So, is there an alternative way?
    My objective is write a program to create movie file of any Java 3D animation.
    Pls advise me. Thanks a million.

    I'm curious as to why FRAPS will record java3d and
    not a java2d app? is there something that Java3d
    sets that makes it recognizable by fraps? or?? could
    someone or messengers ( =D!) explain this for me?Seems that only in JDK 5.0 or later, does the 2D api automatically use a DirectX or OpenGL rendering pipeline (if available).
    Further, these automatic pipelines accelerate polygons and the like, but not low level Graphics2D bit blitting operations.
    There are JOGL apis that allow better control over acceleration, and are considered 'thread safe' (single threaded) whereas DirectX pipelines are not.
    Interesting demos of this here:
    https://jogl-demos.dev.java.net/applettest.html
    and
    http://www.hardcorepawn.com/RandomGL/
    Fraps (commercial) and Taksi (opensource) will reveal that you are actually using acceleration, since they intercept the pipeline at the openGL (and DirectX) level.

  • How to create a executable file from .java file?

    Well usually we would compile and run our program using jdk1.x. Can we create a .exe file so that it will run everytime I open it without compile and run it?
    Regards,
    Ng

    hai,
    you can create a batch file,in it define the commands javac and java.so that whenever u are running the batchfile it is compiled and the program is executed..
    it will work..
    bye,
    j.mouli

  • How to create the ini file for java programms

    hi all,
    I have one problem that is ...
    In my project I am using the JDBC connection ...
    in this I am connecting different connections (means differenet usernames and passwords)...
    for this evrey time I have to change the username and password in the
    hardcode ...
    I think that some ini file are there in java ...
    So if anyone knows about use of ini files in java please
    send me..
    thanks........

    In java they are called properties files.
    Look at java.util.Properties which provides methods for reading, writing, etc.

  • How to create an exe file in java

    hi all,
    i am trying to create exe file for myapplication plz helpme out in this

    hi
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=5133369
    The answer is there in Last Post of this Thread
    Hope it will help you
    Thank you

  • How to convert csv files into java bean objects?

    Hi,
    I have a CSV file, I want to store the data availabale in that csv file into java bean, I am new to this csv files how can I convert CSV files into java beans.
    Please help me.
    Adavanced Thanks,
    Mahendra

    You can use the java.io API to read (and write) files. Use BufferedReader to read the CSV file line by line. Use String#split() to split each line into an array of parts which were separated by comma (or semicolon). If necessary run some escaping of quotes. Finally collect all parts in a two-dimensional List of Strings or a List of Javabeans.
    java.io API: [http://www.google.com/search?q=java.io+javase+api+site:sun.com]
    java.io tutorial: [http://www.google.com/search?q=java.io+tutorial+site:sun.com]
    Basic CSV parser/formatter example: [http://balusc.blogspot.com/2006/06/parse-csv-upload.html]

  • How to import an .csv file into the database?

    and can we code the program in JSP to import the.csv file into the database.

    It is better to use Java class to read the CSV file and store the contents in the database.
    You can use JSP to upload the CSV file to the server if you want, but don't use it to perform database operations.
    JSPs are good for displaying information on the front-end, and for displaying HTML forms, there are other technologies more suitable for the middle layer, back end and the database layer.
    So break you application into
    1) Front end - JSPs to display input html forms and to display data retrieved from the database.
    2) Middle layer - Servlets and JavaBeans to interact with JSPs. The code that reads the CSV file to parse it's contents should be a Java Class in the middle layer. It makes use of Java File I/O
    3) Database layer - Connects to the database using JDBC (Java Database Connectivity), and then writes to the database with SQL insert statements.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Keeping the above concepts in mind, first build a simple JSP and get it to work,
    then research on Google , for Java File I/O , discover how to read a file,
    Then search on how to readh a CSV file using Java.
    After researching you should be able to read the CSV file line by line and store each line inside a Collection.
    Then research on Google, on how to write to the database using JDBC
    Write a simple program that inserts something to a dummy table in the database.
    Then, read the data stored in the Collection, and write insert statements for each records in the collection.

Maybe you are looking for

  • Free Text e-mail in Portal UWL

    HI All, I have a step in my workflow that allows a user to enter a free text message which can be sent to one or more other users. A decision task comes into the users inbox. If they click reject the next step of the workflow is the task which allows

  • How to get exit status of multiple threads

    Hello Everyone, Please let me know how to solve the below problem. I have one main thread. It creates 10 threads and joins them. Now i am interested in the exit status of each of the individual thread. Please let me know how to get the exit status of

  • Cs2 on xp, missing plug-ins

    I created an indesign document a few days ago, I opened the application, and tried to open the file, I get an error message, cannot open file, missing plug-ins: lilo.apln and cellstyles.rpun, if you click ok, then a then it says, cannot open file, an

  • Help : VM 1.2 crashing

    Hi, I have the following problem: We run a servlet which heavily uses database access via jdbc:odbc. It runs on WinNT and 2000 with JDK1.2 and JRun 2.3.3. Now the problem is: The VM is crashing (with Dr.Watson c00000005 - I think this mean Access vio

  • Why am I required to provide a Title when filling in my credit card information?

    The only options they have available are Dr., Mr., Mrs., and Ms.  Why does Apple need to know what is in my pants? And why, if I'm female, does Apple want me to imply my marital status, but not if I'm a male?  And why are Doctors exempt from this ant