Problem in writing data in file......

i am having problem in passing a String object path ;
taken from user in following way
FileWriter fw = new FileWriter(path,append);
error is : (The filename, directory name, or volume label syntax is incorrect)
but if i am using
FileWriter fw = new FileWriter("f.txt",append);
it works...
but i want filename from user... how to achieve this

class writeData
     public String getName()
                    String name=null;
     try
          char c;
          StringBuffer bf=new StringBuffer();
          System.out.print("Enter the File Name:- ");
          while((c=(char)System.in.read())!='\n')
               bf.append(c);
          name=bf.toString();
          catch(Exception e)
          System.out.println("Error is:-"+e);
          return name;
public void wfile(String name1)
          try
          String path ="D:/fname.txt";
          boolean append = true;
          FileWriter fw=new FileWriter(path); // its not working....
          //FileWriter fw=new FileWriter("D:/fname.txt");
          catch(Exception e)
               System.out.println("Error is :- "+e);
public class bravo
     public static void main(String args[])
          writeData wd = new writeData();
          String n = wd.getName();
          wd.wfile(n);
}

Similar Messages

  • Problem while writing data on xls file using jxl API

    Hi,
    I am getting problem while writing data on excel file using jxl api.
    When i write data on file and all handles associated to the file are closed, file size increases but when i open the file nothing is written in it and when file is closed manually from excel window, file size decreased to its original that was before writing data.
    here is code:
              FileOutputStream os = new FileOutputStream(this.dirPath + this.fileName, true);
              WritableWorkbook this.workbook = Workbook.createWorkbook(os);
    after writing data following handler are closed:
    this.os.flush();
                        this.workbook.write();
                        this.workbook.close();
                        this.os.close();
                        this.os = null;
    can any body help me.
    Thanks in advance

    Err, I did help you. I did understand your problem; and I solved it for you. What was missing was that you apparently made no effort to understand what you were being told. Or even consider it. You just argued about it, as though you were the one with the solution, instead of the one whose code didn't work.
    And the other thing that was missing was the part where you said 'thank you' to me for solving your problem. Somewhat more appropriate than biting the hand that fed you, frankly. I do this for nothing, on my own gas, and it's extremely irritating when people keep asking about problems I have already solved for them. I am entitled to discourage that. It's part of making them more efficient actually.
    But it happens often enough that it also makes me think I'm just wasting my time. Probably I am.

  • Problem in writing data to flat file

    Hi,
    I have created an interface with table as source and file as target. My interface is running from long time but its not writing data into file. Any clue?
    -Chikk

    Hi,
    Please, take a look if the target file is locked.
    Try to delete it and put the "Truncate" option from IKM to yes.
    Cezar

  • Problem in writing data to excel spread sheet using jdbc

    Hi Friend,
    I have written a jdbc application ,that retrives data from oracle8i database and writes to excel spread sheet.
    Here I am facing a problem while writing date vales to the spread sheet.
    It is just writing 00.00.0 , instead of a date like 21/10/2005, where I am going wrong , can any one guide me.
    Thanks in advance.

    Don't cross-post!
    http://forum.java.sun.com/thread.jspa?threadID=643815&tstart=0
    Especially when you already got your answer in the other post jackass. If you don't understand the answer then say so there.

  • Time Stamp problem while writing data into the excel file

    Hii, All
                  I am taking the data from the DAQ card of the TOPSCCC with the 8 ms of scanrate for each channel and there are total 16 no of Analog channels in the Card, now i am acquiring the data from the card, time stamping it and writing it into the excel file, which is tab delimited, now the problem is, the data which are in the excel file have the same timestamp for 4 to 5 continuous records, instead we want each data with the different and continuous time stamp with same difference of time stamp between two records, mean if it is difference of 8 ms then it should be the 8 ms for all, but here it is taking the differnce of 16 ms for two samples and giving same time stamp for four to five records and that shouldn't happen, here i am attaching my vi, drivers for the cards and Excel file with the data, can you please give me any suggestion how to do it?
           Please help me i require this suggestion as early as possible, i am requiring it urgently.
    Thanks in Advance,
    Nishant
    Attachments:
    2026vi.llb ‏319 KB
    2026_ScanMultAD_Demo_time.vi ‏80 KB
    Data.xls ‏357 KB

    Hello Nishant,
    that's what I meant:
    Message Edited by GerdW on 05-16-2006 10:32 AM
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    timestamp-array.png ‏2 KB

  • Problem in writing to the file

    I use this labview code to read and save some electrical measurement data from a set of instruments. I am having a problem that the code stops writing to the file after a while. It stops responding too. The only way to stop it then is to use the task manager and kill it. The code was written for an older version of labview but now I am using labview 9. Everything else seems updated but there's a section that uses Write characters to file vi and that may be causing the problem. I made a few futile attempts to change it. I would highly appreciate if someone takes a look at it and could tell me what's going wrong.
    Attachments:
    JANUS 2.2_4K Probe edit (2).vi ‏60 KB

    I will second aeastet's advice - please look into how state machines and producer/consumer loops work and use them.  Your program is very inefficient, but is very similar to what I would have written before I learned about state machines and producer/consumer loops.  Start with the LabVIEW help and go from there.  These forums and the National Instruments website can give you lots of help.
    Two things that will help you for this particular problem:
    At every loop iteration, you are opening the file, seeking to the end of it, appending data, then closing the file.  This is very slow and the code you use, as mentioned above, will not work if the file size exceeds 2GBytes.  I would recommend you open the file once, then use the write primitive to write to it until you finish, then close it.  You do not need the write character to file VI.  No seeking.  No repetitive opening and closing.  You can either open and close outside the loop, or use case structures and boolean flags (as you have done for other things) to open and close inside the loop.
    After you write to the file, if you choose to graph, you are reopening the file, reading the entire thing, and plotting this data.  This is another major slowdown that will only get worse as your file gets bigger.  You would be far better off caching the data in a shift register and plotting it on demand.  It would probably take less memory, as well.  You may want to read the tutorial Managing Large Data Sets in LabVIEW.
    One last tip.  You use Value properties to read and set the values of front panel controls.  Local variables are far faster (about three orders of magnitude).  However, do not make the mistake of using local variables for data storage.  Data is wires.  Local variables are a way to communicate to the front panel.  You seem to have this down, but a reminder to others reading this thread is in order.
    Let us know if you need more explanation or help.  Good luck!
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • Facing problem in writing data to excel sheet using ActiveX

    Hi.
    I want to write data from a one dimesional array to a particular excel sheet in a particular row.Please see the attached vi for explantion.
    It is giving error.But If I give a new file name when the appliation is getting closed it is writing data to the new excel file.
    Please help.
    Thanks in advance
    Attachments:
    Excel sheetWrite.vi ‏90 KB

    Thanks Jhoskin and Rudi .......
    I am able to write data to excel sheet now. I am attaching one"test.zip" file that contains a VI named "Squence.vi "that contains another subVI named "Write U94006 Table To XL.vi"which does the functionality of counting the number of rows in the excel sheet and writing data in the next blank row. I am using the same subVI in the VI named "Sequence.vi"two times so it is taking a lot of time in opening and closing the excel sheet. Will you please suggest some way of calling the subVI only one time.
    Rikki
    Attachments:
    Test.zip ‏105 KB

  • Problem while writing in a file

    Hi,
    i want to write some bytes in a file but it is producing an error
    error:
    ====
    java.io.FileNotFoundException: C:\Documents and Settings\rrus\My Documents\data.pkcs7data (The system cannot find the path specified)
    code:
    ====
    File obj_file = new File(System.getProperty("user.home")+"/My Documents/Signature.sig");
    if(!obj_file.exists())
    obj_file.createNewFile();
    FileOutputStream obj_fout = new FileOutputStream(obj_file);
    obj_fout.write(m_bData); // m_bData is byte array
    obj_fout.flush();
    obj_fout.close();

    And:
    C:\Documents and Settings\rrus\My Documents\data.pkcs7data
    File obj_file = new File(System.getProperty("user.home")+"/My Documents/Signature.sig");Something doesn't quite match here. Your eror message does not match your code.

  • Problem of writing data into a txt. file

    How can I write the product1 object into the testing.txt?
    Product product1 = new Product();
      product1.addNewProduct(1234, "coffee", 0.89, 23, 23.4, "12/12/2008", "catCoffee", "20/11/2007");
      try
        FileWriter writer = new FileWriter("C:\\Documents and Settings\\Charles\\My Documents\\testing.txt");
       // How can I write the product1 object into the testing.txt?
        writer.write("Testing");
        writer.close();
      catch (IOException ex)
          ex.printStackTrace();
      }

    Using ObjectOutputStream with a FileOutputStream is relatively easy but it won't produce a "text" file. If your desire is to produce a file that is human readable you'll need to go another route.
    by using ObjectOutputStream with a FileOutputStream u will have to read UTF or byte(for String) and write UTF or byte (forString)..
    try using
    PrintWriter abc=new PrintWriter(new FileWriter(Filename));
    /// and to write into filename use
    abc.println(String or may be product1.addNewProduct);

  • Problem in writing data to excel spread sheet

    Hi Folks,
    I have developed a jdbc application that writes data to excel spread sheet.while trying to write data to excel, it could not write date values properly.it is writing 00.00.0 for all the date feilds.
    Can some one help here.
    Thanks in advance.

    You can try VistaJDBC at http://www.easyhr.com.au/software/easy_mdb_mde_compactor.htm .
    Otherwise you can write your code to csv/xml/dbase III format, since Excel can open those file format easily.

  • Problem in writing to CSV file

    Hi all,
    i am retreiving a long String which is not in a proper format (ie) Lot of Spaces in between and my String contains comma(,) seperated and I am trying to put that string in to a CSV file. I am able to write the data in the CSV file but not in a proper format.i need to write the data in the below format.
    For Ex:
    Emp-No,Address,Name,Manager -------> this is Heading
    1000,abcd,name,Man-name -----> After i have to put the data in next line
    My String will be like this,
    abcd , , , jsjsj, , ,saalkj,jfjfjfjf,mmm, nnn, , ,
    I am able to get the data properly in the CSV format.
    Please help me to solve this. Thanks in Advance!!!!

    Are you using any reporting frameworks like Jasper
    Reports or you using simple select queries in MySQL
    to export the data to CSV format.Detail more clearly
    to get assist from others.
    Are you using Session beans or Entity beans on Weblogic?no no no, he can create the csv file, whether its in the correct format is the problem of the consumer of this csv file, isnt'it?
    are you using a microsoft product?

  • PSE10 not writing dates to files consistently

    I asked essentially this question on Elements Village a few days ago.  No responses as yet, so I thought I'd try here...
    In PSE10, I have many photos scanned to TIFFs. In the Organizer, I set the dates for these photos to match when the original photo was taken (which of course is not present in the automatic metadata for the scanned image). However, when I look at the actual photo files (either with exiftool, or looking at the metadata available in Windows Explorer on my Windows 7 machine), usually my added date is not present. If it is there, I see a "Date taken" in Explorer. In exiftool, it appears in a few places, including IPTC Date Created and XMP-xmp:Create Date. However, it only appears in about 5-10% of the files. The ones where it does appear seem random to me.
    I have this problem after doing Write Keyword Tags and Properties Info to Photos, although I'm thinking this isn't a factor with this problem.
    Does anyone know how to get these added dates to be written reliably to the files?  And why is it intermittent with PSE10?
    Thank you,
    Bill

    An update, and some more questions:
    I figured out which dates get written to files and which do not.  If my assigned date is only the year, or only month and year, it does not get written to the file.  It is necessary to have the day specified (but not the time) to have it written to the file.  So some new questions:
    If you only specify a year, or year and month in Lightroom, does it write it to the file?  What about other programs, such as Picasa?  Does it support year only dates?
    I remember in the past reading a John Ellis FAQ where he suggested when you only had the year to put in Jan 1st, etc.  I can see how this trick would solve my immediate problem, even tho it is misleading.  My question is the following.  Lets say I plan to convert to Lightroom in the near future.  If I added these artificial Jan 1st's, etc., would that mess up me up after importing into Lightroom?
    Thank you,
    Bill

  • Writing data into file from URL address

    Hi!
    I need to download file from certain url address and write it to file on my local disk. The file being downloaded is a image file and therefore
    I cannot make sure what encoding should I use. When I save file manually on disk and compare it with the file written programmatically, then
    the bytes in both files are not equal. Any smart advises are welcome.
    The code being used is:
    import java.net.*;
    import java.io.*;
    public class UrlParser {
         public static void main(String[] args) {
              String data;
              try{
                   // Construct a URL object
                   URL url = new URL("http://stockcharts.com/c-sc/sc?s=qqqq&p=D&b=3&g=0&i=t74934638175&r=4028");
                   // Open a connection to the URL object
                   String encoding = "UTF8";
                   BufferedReader html = new BufferedReader(new InputStreamReader(url.openStream(),encoding));      
                   Writer img_out = new OutputStreamWriter(new FileOutputStream("sc.gif"), encoding);
                   while((data = html.readLine()) != null) {
                        img_out.write( data );
                   img_out.close();
              } catch(MalformedURLException e) {
                   System.out.println(e);
              } catch(IOException e) {
                   System.out.println(e);
    }

    Use InputStream and OutputStream classes, not Readers/Writers. The latter are for "text" I/O, not "binary".

  • Problem with loading  data from file in ../demo/file/test

    hi there,
    I am using ODI to load text files located on a UNIX server where ODI is installed.
    I am using the FILE_GENERIC data server and physical schema that came with ODI and I can reverse and load the demo files located in ../demo/file
    I created a sub-directory 'test' under ../demo/file and placed a file there.
    When I try to reverse this file (in directory ../demo/file/test) I get the error 'The directory ../demo/file/test specified in your schema does not exist'
    I am sure the userid has equal rights to both directories ../demo/file and ../demo/file/test
    What could I be missing?

    In the topology manager
    1. in the logical architecture : If it doesn't already exists (it should exist if your can use it on your local PC), you import the file technology
    2. In the physical architecture, you create your data server for files .In your case, it shoud already exist for same reason as above. Is has a blue icon under the file technology
    2. Select the Data Server, right click and select Insert Physical Schema . The Physical Schema window appears. On Definition tab, enter a name and then the path of your directory in the data schema field. No need to enyter a work schema for files.
    4. Go to the Context tab, Select a Context and an existing Logical Schema for this new Physical Schema.
    Select an existing Context in the left column, the type the name of a Logical Schema in the right column. This Logical Schema is automatically created and associated to this physical schema in this context.
    It should work but i have never experienced it on a Linux system...

  • Problem in writing to a file

    hi all ...
    i am writing a simple html to a file in swing applicaiotn,the file is created but the content is not writing what may be the reason..can any one help me......
    Thanks
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    import java.lang.*;
    import java.sql.*;
    import javax.swing.filechooser.*;
    public class MyAppFrame extends JFrame implements ActionListener{
         //-- class members
         JTextField jtf_Text;
         JButton jb_Button,G_Button;
         JList j1_List;
         Vector v;
    private JScrollPane jpane;
    final JFileChooser fc = new JFileChooser();
    MyAppFrame(String title) {
         super(title);
         setSize(600,500);
         Container contentPane = getContentPane();
         contentPane.setLayout(new BorderLayout());
              JPanel panel = new JPanel();
         panel.setLayout(new FlowLayout());
              panel.add(new JLabel("Target Folder: "));
    panel.add(jtf_Text = new JTextField(10));
    jb_Button=new JButton("List");
    jb_Button.addActionListener(this);
    panel.add(jb_Button);
    G_Button=new JButton("Generate");
    panel.add(G_Button);
    G_Button.addActionListener(this);
    contentPane.add(panel,BorderLayout.NORTH);
    panel = new JPanel();
              panel.setLayout(new GridLayout(2,1));
              panel.add(new JLabel("Selected Forms:"));
    v=new Vector();
    panel.add(j1_List = new JList());
    //j1_List.setEnabled(false);
    jpane = new JScrollPane();
    jpane.getViewport().add(j1_List);
    contentPane.add(panel, BorderLayout.CENTER);
    panel.add(jpane);
              addWindowListener(new ExitListener());
         setVisible(true);
         public static void main(String[] args) {
         MyAppFrame maf = new MyAppFrame("Form Selection");
    class ExitListener extends WindowAdapter{
    public void windowClosing(WindowEvent event) {
    System.exit(0);
    private void con(){
              Connection con=null;
         ResultSet rs=null;
         try{
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         con = DriverManager.getConnection("jdbc:odbc:satya");
         System.out.println("Set Connection");
         Statement st=con.createStatement();
         String query="select form_name from form";
         System.out.println(query);
    rs=st.executeQuery(query);
    while(rs.next()){
              String name = rs.getString("form_name");
              //JLabel l=new JLabel(name);
              //j1_List.add(l);
              v.add(name);
              // System.out.println(name);
                   j1_List.setListData(v);
                   catch(Exception e)
    e.printStackTrace();
    public void actionPerformed(ActionEvent e) {
    String flag = e.getActionCommand();
    if(flag.equals("List")){
    this.con();
    else
         StringBuffer sb = new StringBuffer();
         sb.append("<html><h1>Hai</h1></html>");
         String formname=(String)j1_List.getSelectedValue();
         String Dir=jtf_Text.getText();
         Dir +="\\0ne.txt";
         if(formname!=null && Dir !=null)
         try
         PrintWriter out= new PrintWriter(new FileWriter(Dir));
    //BufferedWriter br=new BufferedWriter(out);
         out.println(sb);
    catch(Exception e1)
    System.out.println(e1);
         //jb_Button.setEnabled(false);
    //jb_Button.addActionListener(this);
    //StringBuffer Sb = new StringBuffer();

    http://forum.java.sun.com/thread.jsp?forum=57&thread=299655

Maybe you are looking for