Is File handling in Java Swing possible?

Hi I need to know whether file handling in Java Swing is possible or not?

cents wrote:
Thanks for ur answer.....Actually I just wanted to know whether "Reading from a file" and "Writing to a file" in Java Swing is possible or not?
Edited by: cents on Mar 16, 2010 9:35 AMWhat did google tell you? Did you see anything interesting in the API?

Similar Messages

  • Object file handling giving java.io.StreamCorruptedException

    Hi All,
    I am storing and retriving objects from a file. but when i write multiple objects then while reading objects from the file its giving
    java.io.StreamCorruptedExceptionPlease advice. Here's the code
    import java.io.*;
    class Person implements Serializable{
         String name = null;
         int age = 0;
         public void setName(String name){
              this.name = name;
         public String getName(){
              return this.name;
         public void setAge(int age){
              this.age = age;
         public int getAge(){
              return this.age;
    public class ObjectFileRead{
         public static void main(String args[]){
         try{     
         *     Writing the objects to the file
              FileOutputStream out = new FileOutputStream("Person.dat",true);
              ObjectOutputStream objOutStream = new ObjectOutputStream (out);
              for(int i=0;i<5;i++){
                   Person p = new Person();
                   p.setName("MyName:1"+i);
                   p.setAge(10+i);
                   //System.out.println(p.getName());
                   //System.out.println(p.getAge());
                   objOutStream.writeObject (p);
              objOutStream.flush();
              objOutStream.close();
         *     Reading the objects fromt the file;
              FileInputStream inStream = new FileInputStream ("Person.dat");
              ObjectInputStream objInStream = new ObjectInputStream (inStream);
              try{
                   while(true){
                        Person p = (Person)objInStream.readObject();
                        System.out.println(p.getName());
                        System.out.println(p.getAge());
              }catch(EOFException e){
         }catch(Exception e){
              System.out.println(e);
    }

    The output of ObjectOutputStream starts with a header. Because you append to the file Person.dat you end up with multiple headers, but you only open one ObjectInputStream. One approach would be to create a new ObjectInputStream wrapping inStream after every 5 objects read. I suspect a better one (because it avoids the risk of ObjectInputStream doing read-ahead and buffering) is to replace the appending with reading the file and writing it out again followed by the new objects.

  • How to load a text file in a Java swings application

    hi,
    I am trying to retrieve a Java code(or say any text from an existing file) and display it in a swing application.
    I am not able to do so.
    Please help me.

    public String readFile(File f){
              try {
                   BufferedReader read = new BufferedReader(new FileReader(f));
                   String line = read.readLine();
                   String total = "";
                   while(line != null){
              //          System.out.println(line);
                        total += line;
                        line = read.readLine();
                   read.close();
                   return total;
              } catch (Exception e){
                   e.printStackTrace();
              return "";
         }that will read a file into a string, i hope you can figure out the rest

  • Best practice: tar file handling through java on Linux

    What would be the better way to handle large size tar files (size may be more 1 GB) on Linux using Java? One way would be by using linux "tar" command through Runtime.exec, another option is through Java zip classes?
    Btw, functionality I am doing is extract the large tar file, remove some files and tar it back to make a smaller size tar ball. I am not too sure if Java provides an api to remove individual files/directory from a zip file.

    A tar file is not a zip file.
    Java provides no classes that handle .tar files by default.
    It does provide classes to handle the gzip compression that's often applied to .tar files (resulting in .tar.gz or .tgz files).
    So you either search for a library that handles tar files in Java or invoke tar as an external process.

  • Use Adobe Reader (or others) in Java Swing

    Hi,
    is there an adobe solution to show pdf files inside an java swing application?
    Regards
    Arno

    >(1.)Is there a limit to saving the form data?
    It is my understanding that you can harvest data from a form 500 times whether that be from one user of 500 users.
    >(2.)If there is a limit to saving the form like 500 times, can the same form be recreated and the limit of 500 starts all over again
    You'd probably be walking on thin ice by trying that. Could be a loophole but maybe not.
    >(3.)Do I need to purchase a license to save these form data?
    Not if you stay within the limit that is stated in the EULA.
    >(4.)How many forms can have enable usage rights in Adobe Reader per Adobe Acrobat professional?
    Different forms? As far as I know there is no limit to the amount of different forms you use.
    In my opinion, if you think you are going to go anywhere near the limitations of the EULA, consult with your attorney before proceeding. The form enabling function was never intended for large business use. Adobe has another, more costly, solution for that.

  • Loading large files in Java Swing GUI

    Hello Everyone!
    I am trying to load large files(more then 70 MB of xml text) in a Java Swing GUI. I tried several approaches,
    1)Byte based loading whith a loop similar to
    pane.setText("");
                 InputStream file_reader = new BufferedInputStream(new FileInputStream
                           (file));
                 int BUFFER_SIZE = 4096;
                 byte[] buffer = new byte[BUFFER_SIZE];
                 int bytesRead;
                 String line;
                 while ((bytesRead = file_reader.read(buffer, 0, BUFFER_SIZE)) != -1)
                      line = new String(buffer, 0, bytesRead);
                      pane.append(line);
                 }But this is gives me unacceptable response times for large files and runs out of Java Heap memory.
    2) I read in several places that I could load only small chunks of the file at a time and when the user scrolls upwards or downwards the next/previous chunk is loaded , to achieve this I am guessing extensive manipulation for the ScrollBar in the JScrollPane will be needed or adding an external JScrollBar perhaps? Can anyone provide sample code for that approach? (Putting in mind that I am writting code for an editor so I will be needing to interact via clicks and mouse wheel roatation and keyboard buttons and so on...)
    If anyone can help me, post sample code or point me to useful links that deal with this issue or with writting code for editors in general I would be very grateful.
    Thank you in advance.

    Hi,
    I'm replying to your question from another thread.
    To handle large files I used the new IO libary. I'm trying to remember off the top of my head but the classes involved were the RandomAccessFile, FileChannel and MappedByteBuffer. The MappedByteBuffer was the best way for me to read and write to the file.
    When opening the file I had to scan through the contents of the file using a swing worker thread and progress monitor. Whilst doing this I indexed the file into managable chunks. I also created a cache to further optimise file access.
    In all it worked really well and I was suprised by the performance of the new IO libraries. I remember loading 1GB files and whilst having to wait a few seconds to perform the indexing you wouldn't know that the data for the JList was being retrieved from a file whilst the application was running.
    Good Luck,
    Martin.

  • How to convert oracle form fmb file to java swing file using Jdeveloper

    how to convert oracle form fmb file to java swing file using Jdeveloper.Please explain with detailes steps if possible or please give a link where it is available
    thanks
    Message was edited by:
    user591884

    There is no automatic way to do this in JDeveloper. I know there are some Oracle Partners offering forms to java conversion, I don't know how much of their tools are automated and done with JDeveloper. With JDeveloper+ADF you basically rewriting the Forms application from scratch (and using ADF is helpful during this process).

  • File diplay concept in java swing

    i want to display pdf page and xml page in java swing.
    whether it is possible.
    pls help

    well i cant understand ur question first.
    if u just wanna display them just as text files just create a text area and use the setText() method and write all the documents content into it(i assume u know how to read a file using streams)
    i dont know whether it will work so simple for pdf files for their document structure might vary.
    for pdf files try using iText API library...
    if u wanna do processing those files use JAXP for xml and iText for pdf...i hope this necessaily answers ur questions.

  • Maximum file size handled by java

    Hi
    What is the maximum file size that java can handle i.e if I need to read a disk file using java, is there any limit on the size of the file being read?

    The size you can handle is not limited... only by your code :-)
    Check MemoryMappedFiles... i handle Gigabyte files with no problem ;-)

  • How to handle the java.policy file ?

    Can somebody tell me how to handle the java.policy file?
    I always get java.net.SocketExceptions and java.security.AccessControlExceptions while connecting to an appserver from an applet.
    What do I have to write in the java.policy file, where do I have to place it and do I have to call it in some way form my applet?
    Thanks in advance.
    don call

    The java.policy file goes in your jre installation directory in .../jre/lib/security (there should be one there already).
    I used it to allow otherwise restricted permissions for an applet using javax.comm. Add something like the following to the file:
    grant codeBase "URL:http://yourDomainName/rootDirectoryOfYourApp/*" {
         permission java.security.AllPermission;
    This will give the applet downloaded from your site all permissions. You might want to give only certain permissions, I don't know.
    Teri

  • Viewing and printing a PDF file from Java Swing Application

    Hello,
    I need to view and print PDF files from Java Swing Application.How do I do that?I appreciate your help.
    Thank you
    Sumana Somareddy

    If you have a link to the URL pointing to the PDF file, you can allow the browser to open it. Then use the print function of the browser to print the PDF document.
    Regards,
    Tak.

  • How to store grid points in a file using Java Swing?

    Please someone help me with any suggestions about how to store the grid points in a file using Java Swing

    Actually i have designed a gridlayout in Java Swing and have added some components to it such as buttons or images....My problem is when I click on any of the cell of the grid,the corresponding cell number should be stored in an external file....Do u have any suggestions on how to do it?

  • How to store the datas in a .txt file in to a JTable in Java Swing

    Hi sir,
    Here i want to know how to store the data's of a .txt file
    in to a JTable in java swing.
    Where here the .txt file like for eg,spooler.txt is in the server and from there it will come to my client machine what i have to do is to take that .txt file and store the datas of the .txt file
    in a JTable.This is what i want.So pls. do help and provide the code as well.I will be thankful.Since i am involved in a project which involves this it is Urgent.
    Thanx,
    m.ananthu

    You can't just display data from a text file in a JTable. You have you understand the structure of the data so that you can parse the data and create a table model that can access the data in a row/column format. Here is an example of a simple program that does this:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=315172

  • Creating file browser GUI using java swing tree

    Hi all,
    I have some questions which i wish to clarify asap. I am working on a file browser project using java swing. I need to create 2 separate buttons. 1 of them will add a 'folder' while the other button will add a 'file' to the tree when the buttons are clicked once. The sample source code known as 'DynamicTreeDemo' which is found in the java website only has 1 add button which is not what i want. Please help if you know how the program should be written. Thx a lot.
    Regards,

    Sorry, don't know 'DynamicTreeDemo'import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    import java.io.File;
    public class Test extends JFrame {
      JTree jt = new JTree();
      DefaultTreeModel dtm = (DefaultTreeModel)jt.getModel();
      JButton newDir = new JButton("new Dir"), newFile = new JButton("new File");
      public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        newDir.setEnabled(false);
        newFile.setEnabled(false);
        jt.setShowsRootHandles(true);
        content.add(new JScrollPane(jt), BorderLayout.CENTER);
        File c = new File("C:\\temp");
        DefaultMutableTreeNode root = new DefaultMutableTreeNode(c);
        dtm.setRoot(root);
        addChildren(root);
        jt.addTreeSelectionListener(new TreeSelectionListener() {
          public void valueChanged(TreeSelectionEvent tse) { select(tse) ; }
        JPanel jp = new JPanel();
        content.add(jp, BorderLayout.SOUTH);
        jp.add(newDir);
        jp.add(newFile);
        newDir.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            TreePath tp = jt.getSelectionPath();
            if (tp!=null) {
              DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode)tp.getLastPathComponent();
              File newFile = new File((File)dmtn.getUserObject(),"foo");
              if (newFile.mkdir()) {
                dmtn.add(new DefaultMutableTreeNode(newFile));
                dtm.nodeStructureChanged(dmtn);
              } else System.out.println("No Dir");
        newFile.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            TreePath tp = jt.getSelectionPath();
            if (tp!=null) {
              DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode)tp.getLastPathComponent();
              File newFile = new File((File)dmtn.getUserObject(),"foo.txt");
              try {
                if (newFile.createNewFile()) {
                  dmtn.add(new DefaultMutableTreeNode(newFile));
                  dtm.nodeStructureChanged(dmtn);
                } else System.out.println("No File");
              catch (java.io.IOException ioe) { ioe.printStackTrace(); }
        setSize(300, 300);
        setVisible(true);
      void select(TreeSelectionEvent tse) {
        TreePath tp = jt.getSelectionPath();
        newDir.setEnabled(false);
        newFile.setEnabled(false);
        if (tp!=null) {
          DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode)tp.getLastPathComponent();
          File f = (File)dmtn.getUserObject();
          if (f.isDirectory()) {
            newDir.setEnabled(true);
            newFile.setEnabled(true);
      void addChildren(DefaultMutableTreeNode parent) {
        File parentFile = (File)parent.getUserObject();
        File[] children = parentFile.listFiles();
        for (int i=0; i<children.length; i++) {
          DefaultMutableTreeNode child = new DefaultMutableTreeNode(children);
    parent.add(child);
    if (children[i].isDirectory()) addChildren(child);
    public static void main(String[] args) { new Test(); }

  • How to play flash files in java swings

    Hi All ,
    I have a requirement in java swings , i want to play advertisements ( flash files in swings )
    can any one provide any example for the above requirement .
    Thank you all for sharing knowledge in this great forum .
    Jerry

    I have a java desktop application which is actually a
    kiosk application. I have to run some promotion
    videos in my application when no user is using the
    kiosk.Will the kiosks all be running the same OS?
    The reason I ask is that JMF is available in both
    standard and performance pack versions. The PP
    provides a wider variety of formats, but runs only
    on Win. and *nix.
    videos can be any avi or neother which can easily be
    played in java applications.That is handy. The JMF standard pack provides
    support for a number of flavors of AVI, but not all.
    What is the best way for me to play video files in a
    java application??I would suggest checking if the 'standard' version
    of the JMF can play* the current AVI's. If it can, use
    the standard JMF for the project, if not, look to
    converting the AVI's to something the JMF can
    deal with, this might involve storing the video or
    audio of the AVI's in a different format - you
    might have to experiment to get the right
    combination, but the JMF 'supported formats'
    is a good guide.
    http://java.sun.com/products/java-media/jmf/2.1.1/formats.html
    * To check if JMF can play them, install it and
    try loading the AVI's in JMStudio - the default
    player.

Maybe you are looking for

  • Weblogic 9.1 - problems running Liferay portal

    I'm working on getting the Liferay portal 3.6.1 working on Weblogic 9.1.           Anyone here succesfully got it working!?           So far i can get the ear file to deploy and start ok, but when i access the page in a browser i get alot of Exceptio

  • Merge rpd and webcat

    Hi All, Can someone give me the pointers where I can know how we merge rpd and webcat. Thanks a lot in advance. Regards, Amrit

  • CProjects-MS Projects Export - Role-Task assignment...

    When I export from cProjects, I have data mismatch from cProjects to MS Project. A task of 5 days is assigned to 3 roles: Role 1 for 2 days Role 2 for 1 day Role 3 for 2 days. However, in MS Project, the Role-Task-Assignment gets uniformly distribute

  • G5 Very Slow Opening Folders, Spinning Loudly

    My brother gave me his practically new G5 when he upgraded to the new latest and greatest. He wiped the drive of everything, including the operating system. I purchased Leopard when I brought the computer to my Apple dealer yesterday because I could

  • Audio Core Overload ( Error -10011) and others.....

    Hello, I was just wondering if anybody had a solution for the Audio Core Overload and the Disk too slow problem. I run a Dual 1.8 with 1 GB of RAM and Logic 7.1 ( recently upgraded form 7.01), Kontakt, DFH. I use the Moto 828 Firwire interface. I nev