Writing to a File Using JFile Chooser!

pls, iam developing a word processor and i am implementing JFileChooser for my file I/O , the OpenFile program works well, but the save File program is not working well any Way?
Thanks.

if it's not an applet, try:
JFileChooser fc = new JFileChooser();
int result = fc.showSaveDialog( this );
if ( result == JFileChooser.APPROVE_OPTION )
String str1 = fc.getCurrentDirectory() +
System.getProperty("file.separator") + fc.getSelectedFile().getName() ;
File f = new File( str1 );
if ( f.exists() )
int answer = JOptionPane.showConfirmDialog(null,"Do you want to save the changes made before closing","Confirm Dialog",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,null);

Similar Messages

  • How to display mutilpe files using JFile choose

    please hepl me regarding how to select and display the mutilpe files using JFile chooser

    i m sorry if i have done any mistakes.i am new to
    this forum i just wanted to tell my problem and wish
    that it could ne solved...Tell it only once. Posting multiple times don't get more attention.

  • Writing to a file using log4j

    Hi ,
    I am facing an issue in rolling out file on an hourly basis. I have a source file , say usagelog_date.log which records logging, then after an hour an hour I have to separate that file , give it a different name say usagelog_date.10.log , I copy the contents of the source file into the rolling file, and make that source file empty. But after making that file empty when I am writing to the file using some threads simultaneously, I get some blank characters first and only after that the logging starts, that increases the file size to a large extent.
    My java code which does this separation is as follows.
    package com.proquest.services.usage.helper;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.nio.channels.FileLock;
    import java.util.Calendar;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    public class UsageRotator {
         private Log scpLog = LogFactory.getLog("SCPLog");
         public String rotateAndReturnFilename(String rotationdate, String location) throws Exception {
              Calendar calendar = Calendar.getInstance();
              int hour_of_day = calendar.get(Calendar.HOUR_OF_DAY);
              String rotationalTime = ((hour_of_day < 10) == true) ? "0" + hour_of_day : "" + hour_of_day;
              String rotatedFileName = null;
              File usageLoggingLogFile = new File(location + "usagelogging." + rotationdate + ".log");
              if (usageLoggingLogFile != null && usageLoggingLogFile.exists()) {
                   File usageLoggingRotatedFile = new File(location + "usagelogging." + rotationdate + "." + rotationalTime + ".log");
                   copyFile(usageLoggingLogFile, usageLoggingRotatedFile);
    //copying the contents of source file to a rolling file
                   FileOutputStream fout = new FileOutputStream();
    // making the source file empty fout.flush();               
                   usageLoggingLogFile.setWritable(true);
                   boolean isEmpty = isFileEmpty(usageLoggingLogFile);
                   if(isEmpty)     
                        scpLog.info("Existing file has been empty so it's good to proceed for looging next occurances");
                   rotatedFileName = usageLoggingRotatedFile.getName();
                   scpLog.info("Log file has been rotated to "+rotatedFileName);
              } else {
                   throw new Exception("File rotation failed : UsageLogging file couldn't be found for the supplied date");
              return rotatedFileName;
         private void copyFile(File source, File destn) throws Exception {
              FileInputStream fis = new FileInputStream(source);
         FileOutputStream fos = new FileOutputStream(destn);
         try {
         byte[] buf = new byte[1024];
         int i = 0;
         while ((i = fis.read(buf)) != -1) {
         fos.write(buf, 0, i);
         catch (FileNotFoundException e) {
         throw new Exception("[ERROR] File copy failed");
         finally {
         if (fis != null) fis.close();
         if (fos != null) fos.close();
         private boolean isFileEmpty(File file) throws Exception {
              FileReader fr = new FileReader(file);
              BufferedReader br = new BufferedReader(fr);
              boolean isEmpty = true;
              while (br.readLine() != null) {
                   isEmpty = false;
              return isEmpty;
    And my log4j file with which I am writing is
    # Default is to send information messages and above to the console
    log4j.rootLogger = DEBUG, DailyLogFileAppender
    # Logger configurations
    #log4j.logger.com.proquest.services.usage=DEBUG, DailyLogFileAppender
    log4j.logger.com.proquest.services.UsageLog=INFO, UsageLogFileAppender
    # Appender configurations
    # Define an appender which writes to a file which is rolled over daily
    log4j.appender.DailyLogFileAppender = com.proquest.services.log.PqDailyRollingFileAppenderExt
    log4j.appender.DailyLogFileAppender.File = logs/usagelogging/usagelogging-error.log
    log4j.appender.DailyLogFileAppender.DatePattern = '.'yyyy-MM-dd
    log4j.appender.DailyLogFileAppender.Append = true
    log4j.appender.DailyLogFileAppender.layout = org.apache.log4j.PatternLayout
    log4j.appender.DailyLogFileAppender.layout.ConversionPattern=%d{ISO8601} %m%n
    log4j.additivity.com.proquest.services.usage = false
    log4j.additivity.com.proquest.services.UsageLog = false
    log4j.appender.UsageLogFileAppender = com.proquest.services.log.PqDailyRollingFileAppenderExt
    log4j.appender.UsageLogFileAppender.File = logs/usagelogging/usagelogging.log
    log4j.appender.UsageLogFileAppender.DatePattern = '.'yyyy-MM-dd
    log4j.appender.UsageLogFileAppender.Append = true
    log4j.appender.UsageLogFileAppender.layout=org.apache.log4j.PatternLayout
    log4j.appender.UsageLogFileAppender.layout.ConversionPattern=%d{ISO8601} %m%n
    Can somebody please suggest me what to do, as I have been badly deadlocked into the problem.
    Thanks
    Suman

    neoghy wrote:
    ... rolling out file on an hourly basis.
    And my log4j file with which I am writing is
    #  Default is to send information messages and above to the console
    log4j.rootLogger = DEBUG, DailyLogFileAppender
    # Logger configurations
    #log4j.logger.com.proquest.services.usage=DEBUG, DailyLogFileAppender
    log4j.logger.com.proquest.services.UsageLog=INFO, UsageLogFileAppender
    # Appender configurations
    #  Define an appender which writes to a file which is rolled over daily
    log4j.appender.DailyLogFileAppender = com.proquest.services.log.PqDailyRollingFileAppenderExt
    log4j.appender.DailyLogFileAppender.File = logs/usagelogging/usagelogging-error.log
    log4j.appender.DailyLogFileAppender.DatePattern = '.'yyyy-MM-dd
    log4j.appender.DailyLogFileAppender.Append = true
    log4j.appender.DailyLogFileAppender.layout = org.apache.log4j.PatternLayout
    log4j.appender.DailyLogFileAppender.layout.ConversionPattern=%d{ISO8601} %m%n
    log4j.additivity.com.proquest.services.usage = false
    log4j.additivity.com.proquest.services.UsageLog = false
    log4j.appender.UsageLogFileAppender = com.proquest.services.log.PqDailyRollingFileAppenderExt
    log4j.appender.UsageLogFileAppender.File = logs/usagelogging/usagelogging.log
    log4j.appender.UsageLogFileAppender.DatePattern = '.'yyyy-MM-dd
    log4j.appender.UsageLogFileAppender.Append = true
    log4j.appender.UsageLogFileAppender.layout=org.apache.log4j.PatternLayout
    log4j.appender.UsageLogFileAppender.layout.ConversionPattern=%d{ISO8601} %m%nCan somebody please suggest me what to do, as I have been badly deadlocked into the problem.I assume you mean [DailyRollingFileAppender ^apache^|http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/DailyRollingFileAppender.html]
    log4j.appender.DailyRollingFileAppender.DatePattern = '.'yyyy-MM-dd-HH

  • How to display all the files that are selected using JFile chooser

    please hepl me i m posting my code here.
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.zip.Deflater;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipOutputStream;
    public class browser extends JFrame
    String curDir;
    JLabel statusbar;
    public browser()
    super("File Chooser Test Frame");
    setSize(1050,600);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    curDir = System.getProperty("user.dir") + File.separator;
    statusbar = new JLabel("Output of your button choice goes here!");
    Container c = getContentPane();
    c.setLayout( null );
    JButton openButton = new JButton("Browse file");
    JButton dirButton = new JButton("Pick Dir");
    JButton resetButton = new JButton("Reset");
    JButton submitButton = new JButton("Submit");
    final JTextArea tf = new JTextArea(100,50);
    final JList l1 = new JList("list");
    tf.setEditable(true);
    // add the open FILE chooser
    openButton.addActionListener(new ActionListener()
         public void actionPerformed(ActionEvent ae)
         JFileChooser chooser = new JFileChooser(curDir);
         chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
         chooser.setMultiSelectionEnabled(true);
    //Java 1.6 can use FileNameExtensionFilter class
    // FileFilter filter=new FileNameExtensionFilter("HTML file","htm","html")
    // chooser.addChoosableFileFilter(filter);
    //Prior versions must use external extension of FileFilter class (ie ExtFilter)
    //ExtFilter requires separate compile to enable choosable selection
         String[] html = new String[] {"htm","html","xhtml"};
         int option = chooser.showOpenDialog(browser.this);
         if (option == JFileChooser.APPROVE_OPTION)
         File[] sf = chooser.getSelectedFiles();
         String filelist = "nothing";
         try
         if (sf.length > 0) filelist = sf[0].getCanonicalPath();
         for (int i = 1; i < sf.length; i++)
         {filelist += ", " + sf[i].getCanonicalPath();
    tf.setText("our choices" + filelist);
         catch (IOException evt) {System.out.println("Exception: "+evt);}
    statusbar.setText("Your choices: " + filelist );
    // String[] text = new String[100];
    //getChars(0,100,text[],0);
    l1.setText("your choices \n" + filelist);
         else {statusbar.setText("You cancelled!");}
    // add the open DIRECTORY chooser
    dirButton.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    JFileChooser chooser = new JFileChooser(curDir);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
         chooser.setMultiSelectionEnabled(false);
    int option = chooser.showOpenDialog(browser.this);
    if (option == JFileChooser.APPROVE_OPTION)
    File[] sf = chooser.getSelectedFiles();
    String filelist = "nothing";
    try
    if (sf.length > 0) filelist = sf[0].getCanonicalPath();
    for (int i = 1; i < sf.length; i++)
              {filelist += ", " + sf[i].getCanonicalPath();}
         catch (IOException evt) {System.out.println("Exception: "+evt);}
    statusbar.setText("You chose " + filelist);
         else {statusbar.setText("You cancelled!");}
    System.out.println("Example of ZIP file creation.");
    // Specify files to be zipped
    String[] filesToZip = new String[1];
    filesToZip[0] = "filelist";
    byte[] buffer = new byte[18024];
    // Specify zip file name
    String zipFileName = "example.zip";
    try {
    ZipOutputStream out =
    new ZipOutputStream(new FileOutputStream(zipFileName));
    // Set the compression ratio
    out.setLevel(Deflater.DEFAULT_COMPRESSION);
    // iterate through the array of files, adding each to the zip file
    for (int i = 0; i < filesToZip.length; i++) {
    System.out.println(i);
    // Associate a file input stream for the current file
    FileInputStream in = new FileInputStream(filesToZip);
    // Add ZIP entry to output stream.
    out.putNextEntry(new ZipEntry(filesToZip[i]));
    // Transfer bytes from the current file to the ZIP file
    //out.write(buffer, 0, in.read(buffer));
    int len;
    while ((len = in.read(buffer)) > 0)
    out.write(buffer, 0, len);
    // Close the current entry
    out.closeEntry();
    // Close the current file input stream
    in.close();
    // Close the ZipOutPutStream
    out.close();
    catch (IllegalArgumentException iae) {
    iae.printStackTrace();
    catch (FileNotFoundException fnfe) {
    fnfe.printStackTrace();
    catch (IOException ioe)
    ioe.printStackTrace();
    c.add(openButton);
    c.add(dirButton);
    c.add(statusbar);
    c.add(resetButton);
    c.add(submitButton);
    //c.add(tf);
    c.add(l1);
    Insets insets = c.getInsets();
    Dimension size = openButton.getPreferredSize();
    openButton.setBounds(745 + insets.left,115 + insets.top, size.width, size.height);
    size = dirButton.getPreferredSize();
    dirButton.setBounds(755 + insets.left,165 + insets.top, size.width, size.height);
    size = statusbar.getPreferredSize();
    statusbar.setBounds(755 + insets.left,215 + insets.top, size.width, size.height);
    size = resetButton.getPreferredSize();
    resetButton.setBounds(755 + insets.left,265 + insets.top, size.width, size.height);
    size = submitButton.getPreferredSize();
    submitButton.setBounds(755 + insets.left,465 + insets.top, size.width, size.height);
    size = tf.getPreferredSize();
    tf.setBounds(25 + insets.left,5 + insets.top, size.width + 150, size.height + 430);
    size = l1.getPreferredSize();
    l1.setBounds(25 + insets.left,5 + insets.top, size.width + 150, size.height + 430);
    setSize(1000,800);
    setVisible(true);
    public static void main(String[] args)
    new browser();

    Start by defining "display". Then continue by reading this:
    http://forum.java.sun.com/help.jspa?sec=formatting

  • Writing into Excel file using PL/SQL and formatting the excel file

    Hi,
    I am writing into a excel file using PL/SQL and I want to make the first line bold on the excel. Also let me know if there are any other formatting options when writing into excel.
    Regards,
    -Anand

    I am writing into a excel file using PL/SQL
    Re: CSV into Oracle and Oracle into CSV
    check that thread or search in this forum...

  • How To use JFile Chooser in a Tabbed Pane Dialog

    I have created a tabbed pane dialog. In one of the tabs I want to add a JFile Chooser.
    How can I approach this problem. also Do I have to use a JDialog with a frame or can I create a JDialog without using a frame and create a instance from the main function.

    I have created a tabbed pane dialog. In one of the
    tabs I want to add a JFile Chooser. Since JFileChooser is a JComponent you could add it to any Container like any other JComponent.
    Maybe you have to do some init by hand which is done normally by the show*() methods of JFileChooser. Taking a look at the source of showDialog() should help.
    Hope that helps,
    Alex

  • Reading and Writing large Excel file using JExcel API

    hi,
    I am using JExcelAPI for reading and writing excel file. My problem is when I read file with 10000 records and 95 columns (file size about 14MB), I got out of memory error and application is crashed. Can anyone tell me is there any way that I can read large file using JExcelAPI throug streams or in any other way. Jakarta POI is also showing this behaviour.
    Thanks and advance

    Sorry when out of memory error is occurred no stack trace is printed as application is crashed. But I will quote some lines taken from JProfiler where this problem is occurred:
              reader = new FileInputStream(new File(filePath));
              workbook = Workbook.getWorkbook(reader);
              *sheeet = workbook.getSheet(0);* // here out of memory error is occured
               JProfiler tree:
    jxl.Workbook.getWorkBook
          jxl.read.biff.File 
                 jxl.read.biff.CompoundFile.getStream
                       jxl.read.biff.CompoundFile.getBigBlockStream Thanks

  • Writing data into files using VHDL Textio

    Hi 
    I was trying to write nos. from 1 to 8 into a text file using the below program.
    process
    type IntegerFileType is file of integer;
    file data_out: IntegerFileType ;
    variable fstatus: FILE_OPEN_STATUS;
    variable coun: natural:= 1;
    begin
    file_open(fstatus,data_out,"myfile.txt",write_mode);
    for i in 1 to 8 loop
    write(data_out, coun);
    coun := coun + 1;
    end loop;
    file_close(data_out);
    wait; -- an artificial way to stop the process
    end process;
    But getting the below attached result..
    Can you please help me out what could be wrong with the program.
    Thanks & regards
    Madhur

    Do you want the numbers in the file to be human readable ASCII?
    Then you'll need to convert your coun to a string. 
    declare another variable of type line (type access to string).
    do a write() to the line, then a writeline() to the file.
    natural'image(coun) will convert coun to a string.
    Google should help you find example code that will help.

  • Writing to a file using an applet?

    I'm trying to write to a .txt file using an applet. When I run the applet from JBuilder everything works perfectly, but when I run it from internet explorer I don't seem to be able to read or write from and to the file... Anyone has an idea? Is it possible to do that?

    Applets run on restricted security priveelege. Unless you sign your applet, you cant access the files from the applet.
    Go through this.. This might help you
    http://developer.java.sun.com/developer/technicalArticles/Security/Signed/

  • Writing to a file using labview

    hello,
    so i wrote this vi to write some data to a text file and that part works correctly.
    the problem i'm having is that, it doesn't append to the file. so for each data point that it writes it requires a new file.
    in otherwords, if i need to write 10 data points the program prompts each time for 10 different file names.
    how do i resolve this so that the program will write all the 10 data points to one file, by appending each time.
    e.g. data points: 29.5, 34.2, 21.34, 543.2 ... etc
    i want something like this:
    29.5
    34.2
    21.34
    543.2
    etc
    thanks
    -r

    If the path is correctly wired, it should not prompt you for another file. Make sure you wire the path to a shift register so it is available the next time the "write charaters ..." is called.
    You can do the "exception" in many ways. Some examples:
    --Check if the file exists, and if so, append.
    --Use a shift register initialized by "false", then wire it to the append terminal. Feed a "true" to the shift register on the right.
    However, you should consider using some of the lower level file I/O and open the file only once, then keep writing data and close it only at the end. The high-level "write characters to file" would need to do a lot of extra work because whenever it is called it opens the file, writes/appends data, then
    closes the file again.
    LabVIEW Champion . Do more with less code and in less time .

  • Problem writing to excel file using report generation toolkit

    hello everyone, i have this report generation toolkit... and i want to output DAQmx Analog I/P data on to an excel sheet. the DAQmx is programmed to collect 
    data at 3samples/sec. however, when i see the excel file that Report Generation Toolkit generates, the time stamp is updated every second instead of every 0.33sec. 
    can anyone please help me?  i am using the MS Office Report Express VI. 
    Now on LabVIEW 10.0 on Win7

    @All, I got rid of the express VI, decided to work on the custom low level VIs instead. however, i have a new problem now... 
    I have a case statement wherein, the user selects if he wants to start generating a report. once the program enters tat loop, the program speed reduces! 
    can anyone please tell me why is it happening? i ahve attached the vi... also another question.. in this VI, i am capturing the unwanted data into the graph as I am indexin the graph input. how can i make a logic 
    that the graph captures the data only when I am switching the CREATE REPORT button (which is in the while loop). is there a way that I can append the data to the graph without creating a new graph every iteration? please let me know
    thanks
    Now on LabVIEW 10.0 on Win7
    Attachments:
    Untitled 7.vi ‏75 KB
    Untitled 7.JPG ‏99 KB

  • Writing an XML file using a Servlet

    Hello, I'm trying to code a servlet that receives a POST from a HTTP and output its data to a XML file, the problem is that I get the following error:
    The XML page cannot be displayed
    Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
    XML document must have a top level element. Error processing resource 'http://localhost:8080/XMLSender/xmlsend'.
    I don't know what happens, because I'm NOT trying to show the content, just to save it, I post my code here so anyone can help me, please. Thanks in advance.
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class xmlsender extends HttpServlet
    public void service(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    ServletOutputStream salida = res.getOutputStream();
    res.setContentType("text/xml");
    String cadenanumero = req.getParameter("numero");
    String cadenaoperadora = req.getParameter("operadora");
    String cadenabody = req.getParameter("mensaje");
    String cadenashortcode = req.getParameter("shortcode");
    File f1 = new File("salida.xml");
    FileWriter writer = new FileWriter(f1);
    writer.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    writer.write("<root>");
    writer.write("<tlf>" + cadenanumero + "</tlf>");
    writer.write("<op>" + cadenaoperadora + "</op>");
    writer.write("<sc>" + cadenashortcode + "</sc>");
    writer.write("<body>" + cadenabody + "</body>");
    writer.write("</root>");
    writer.close();
    }

    Yes, in fact what I want is the file to be in the server, now, I modificated my code to the following:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class xmlsender extends HttpServlet
    public void service(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    ServletOutputStream salida = res.getOutputStream();
    res.setContentType("text/HTML");
    String cadenanumero = req.getParameter("numero");
    String cadenaoperadora = req.getParameter("operadora");
    String cadenabody = req.getParameter("mensaje");
    String cadenashortcode = req.getParameter("shortcode");
    File f1 = new File ("salida.xml");
    FileWriter writer = new FileWriter(f1);
    /*salida.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    salida.println("<root>");
    salida.println("<tlf>" + cadenanumero + "</tlf>");
    salida.println("<op>" + cadenaoperadora + "</op>");
    salida.println("<sc>" + cadenashortcode + "</sc>");
    salida.println("<body>" + cadenabody + "</body>");
    salida.println("</root>"); */
    salida.println("Finalizado");
    f1.createNewFile();
    writer.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    writer.write("<root>");
    writer.write("<tlf>" + cadenanumero + "</tlf>");
    writer.write("<op>" + cadenaoperadora + "</op>");
    writer.write("<sc>" + cadenashortcode + "</sc>");
    writer.write("<body>" + cadenabody + "</body>");
    writer.write("</root>");
    writer.close();
    It still do not create my file "salida.xml", still don't know why. Any help is welcome.

  • Writing to remote files using an applet.

    I programmed a basic game as an applet for a web site, but it really needs some kind of high score functionality.
    I plan to store the high scores in a file in the server. Reading information from the file is no problem at all, but updating the file with new highscores runs into security problems. Obviously I can't simple use a simle file writer to do that. What is the proper way to do this?
    One possibility which came to my mind is to make the applet open a ftp connection to the server and upload the new highscores file to the server. but that would mean hardcoding my password into the applet code.
    Please keep in mind using servlets or any other programs running on the server is out of question.
    Any help greatly appreciated,thanks in advance.

    Why not host this applet on another free server which supports mysql/postgresql/etc and store it in a database? Any hosts/tools needed, just ask - there are several good freeware.
    /DanX

  • Writing Objects to file using Externalizable

    Hi,
    I'm trying to write an object to file. My sample code is:
    public class Junk implements Externalizable{
    private static java.util.Random generator = new java.util.Random();
    private int answer;
    private double[] numbers;
    private String thought;
    public Junk(String thought) {
    this.thought = thought;
    answer = 42;
    numbers = new double[3+ generator.nextInt(4)];
    for (int i=0; i<numbers.length; i++) {
    numbers[i] = generator.nextDouble();
    public void writeExternal(ObjectOutput stream) throws java.io.IOException {
    stream.writeInt(answer);
    stream.writeBytes(thought);
    for(int i=0; i< numbers.length; i++) {
    stream.writeDouble(numbers);
    public void readExternal(ObjectInput stream) throws java.io.IOException {
    answer = stream.readInt();
    String thought = stream.readUTF();
    and the class with main() is:
    package MyTest;
    import java.io.*;
    public class SerializeObjects {
    public SerializeObjects() {
    public static void main(String args[]) {
    Junk obj1 = new Junk("A green twig is easily bent.");
    Junk obj2 = new Junk("A little knowledge is a dangerous thing.");
    Junk obj3 = new Junk("Flies light on lean horses.");
    ObjectOutputStream oOut = null;
    FileOutputStream fOut = null;
    try {
    fOut = new FileOutputStream("E:\\FileTest\\test.bin");
    oOut = new ObjectOutputStream(fOut);
    obj1.writeExternal(oOut);
    //obj2.writeExternal(oOut);
    } catch (IOException e) {
    e.printStackTrace(System.err);
    System.exit(1);
    try {
    oOut.flush();
    oOut.close();
    fOut.close();
    } catch(IOException e) {
    e.printStackTrace(System.err);
    System.exit(1);
    The output I get in test.bin contains some junk ascii codes. The only item that is written correctly in the file is the string.
    Is there anyway I can write correct data into a file?
    My output needs to be a readable text format file.
    Can anyone help please?

    obj1.writeExternal(oOut);This should be
    oOut.writeObject(obj1);However,
    The output I get in test.bin contains some junk ascii
    codes. The only item that is written correctly in the
    file is the string.If you don't want 'junk' don't use Externalizable and ObjectOutputStream at all, just use PrintStream/PrintWriter.println().

  • Writing to a file using url

    Hi all,
    I have build an applet which I am going to put in a web. Right now I am working locally and I'm able to read file's using this code:
    url = new URL("http://localhost/file.txt");
                is = url.openStream();
                BufferedReader bufRdr  = new BufferedReader(new InputStreamReader(is));
                while((line = bufRdr.readLine()) != null)
                  //do things
                bufRdr.close();
                is.close();
            }Now I would like to be able to write in this file. How could I do it?
    Thanks!

    Using HTTP to open a local file will only work if you have a web server running locally, and if that server happens to know how to find and deal with that file.
    If you want to use that same web server to write files locally, then your local web server will need to have functionality to write files.
    So your first issue is dealing with that. How you do this will depend on what web server you're currently running.
    Using a web server might not be the best approach, by the way.

Maybe you are looking for

  • Session variables is not getting updated in JSP

    Hi Floks, I had a situation where in i need to populate the drop down depending on the action perfomed by user in menus. An action method is triggered to load the scneario specific values to drop down here is that    PSSBuilder pssbuilder = new PSSBu

  • Problem with code: reading a string

    Hi, I am very new to java so excuse my naivety. i need to write some code which will decode an encrypted message. the message is stored as a string which is a series of integers which. Eg. Nick in this code is 1409030110 where a = 1, b = 2,... and th

  • Problem in "Save & refresh data" in epm ribbion

    Hi Experts,                  I got a problem in Save data option . I had a report with values but now i changed it into input-form to enter values . After entering my values i'm clicking on SAVE DATA button in epm tab but my problem is it is showing

  • How to insert 2-D array of elements in excel sheet

    I have a 2-D array of elements. I want to insert this array into an excel sheet and display the data in a graph. I used the example "excel insert table" but the problem with that VI is, it is inserting the elements cell by cell which is taking long t

  • Help!  iTunes doesn't recognized any of our devices.  What can I do?

    Help!  iTunes doesn't recognized any of our devices.  What can I do?