Results 1 to 6 of 6

Thread: Is File handling in Java Swing possible

  1. #1
    Join Date
    Apr 2010
    Posts
    58

    Is File handling in Java Swing possible

    I am looking for how to open a file and save a file in Java. My problem, is that I do not how SIAS insert a code in my code already prepared. The Applet class provides everything necessary for image playback:
    Code:
    Image java.applet.Applet.getImage(URL url); Image java.applet.Applet.getImage(URL url, String name);
    Please help.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Is File handling in Java Swing possible

    The DOM API to manipulate XML files easily using their tree structure. This example covers the following:
    * creating an XML document from scratch;
    * writing an XML document to disk;
    * reading an XML document into memory from a file;
    * tree parsing an XML document loaded into memory.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: Is File handling in Java Swing possible

    Java provides a whole class to read and write files. These classes are grouped in a package. For files, this is the package java.io. To use the classes in a package, you need to "import", using the beginning of the file . java, the keyword import, followed by the package name, then a dot and a star. Thus, to import the classes of the package java.io, we begin the file:
    Code:
    import java.io. * public class
    Once this line added, you have access to classes for manipulating Java files. Among these classes, two classes of interest here: FileReader and FileWriter, which we will respectively permettrent to read and write files.

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Is File handling in Java Swing possible

    To read a file, so the class FileReader that we use. More precisely, it creates a new object of this class for each file you want to read, using the constructor that takes a parameter file name to read. The creation of this object to the effect of opening the file read. To open the file foo.txt in reading, one can for example do:
    Code:
    FileReader fr = new FileReader ("foo.txt");

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Is File handling in Java Swing possible

    There are two ways to access the files: sequentially, whereas in a file as a stream, and randomly (random), which can move anywhere in the file in any order. In C, these two ways of doing things are mixed, but in Java we can clearly distinguish the sequential access mode that applies to data streams (streams), and random fashion, mainly implemented through the RandomAccessFile class.

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Is File handling in Java Swing possible

    Once the file is opened, it uses the object created to read characters in the file, using the method read () class FileReader. Note, however, this method does not return a character, but an integer that represents the code character or the value -1 if we reached the end of the file. It is therefore necessary to store the character code read in an integer, test whether or not the integer is -1, then convert character through the conversion (float).

Similar Threads

  1. Applets V/s Swing in JAVA
    By "Dritan" in forum Software Development
    Replies: 3
    Last Post: 14-12-2010, 09:04 AM
  2. Entitymanager handling with JPA in Swing application
    By Zia 7 in forum Software Development
    Replies: 4
    Last Post: 30-07-2010, 02:33 AM
  3. Print in java using Swing
    By Sheenas in forum Software Development
    Replies: 3
    Last Post: 18-11-2009, 09:50 AM
  4. Java Swing and MySQL
    By shelton141 in forum Software Development
    Replies: 1
    Last Post: 22-09-2009, 08:50 AM
  5. Java swing help with repaint()
    By grudge in forum Software Development
    Replies: 4
    Last Post: 23-07-2009, 03:41 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,913,152.59755 seconds with 17 queries