Télécharger document package java.io

Classes

— class File
— final class FileDescriptor
— abstract class InputStream
— class ByteArrayInputStream
— class FileInputStream
— class FilterInputStream
— class BufferedInputStream
— class DataInputStream (interface DataInput)
— class LineNumberInputStream
— class PushbackInputStream
— class PipedInputStream
— class SequenceInputStream
— class StringBufferInputStream
— abstract class OutputStream
— class ByteArrayOutputStream
— class FileOutputStream
— class FilterOutputStream
— class BufferedOutputStream
— class DataOutputStream (interface DataOutput)
— class PrintStream
— class PipedOutputStream
— class RandomAccessFile (interfaces DataInput,DataOutput)
— class StreamTokenizer

Interfaces

Interface DataInput
Interface DataOutput
Interface FilenameFilter

Exceptions

2.27 Class EOFException
2.28 Class FileNotFoundException
2.29 Class IOException
2.30 Class InterruptedIOException
2.31 Class UTFDataFormatException

Constructeurs

fichiers d’entrée

FileInputStream fis=new FileInputStream("toto");
DataInputStream d=new DataInputStream(fis);

fichiers de sortie

File f= new File(“toto”);
FileOutputStream fos=new FileInputStream(f);
DataOutputStream d=new DataOutputStream(fos);

flots standards

public final class java.lang.System extends java.lang.Object{
// Fields
public static PrintStream err;
public static InputStream in;
public static PrintStream out;
// Methods
public static void arraycopy(Object src, int src_pos,
Object dst, int dst_pos, int length);
public static long currentTimeMillis();
public static void exit(int status);
public static void gc();
public static Properties getProperties();
public static String getProperty(String key);
public static String getProperty(String key, String def);
public static SecurityManager getSecurityManager();
public static void load(String filename);
public static void loadLibrary(String libname);
public static void runFinalization();
public static void setProperties(Properties props);
public static void setSecurityManager(SecurityManager s);
}
System.out.println(System.in.getClass().getName());

exemples d’utilisation des flots standards

import java.io.*;
public class lecture {
static public void main(String[] args)
{int x=0;
System.out.print("saisie :");
System.out.flush();
try
{x=System.in.read();
System.out.println(System.in.available()+
" car. sont en attente.");
}
catch (IOException e)
System.out.println(e.getMessage());
System.out.println("int lu :" + x);
System.out.println("car. lu :" + (char) x);
}
}

exemples d’utilisation des flots standards

import java.io.*;
public class majuscule2 {
static public void main(String[] args)
{int x=0;
System.out.print("saisie :");
System.out.flush();
try{
do
{x=System.in.read;
System.out.println(Character.toUpperCase((char) x));}
while (System.in.available()>0);
System.out.println(System.in.available()+
" car. sont en attente.");}
catch (IOException e)
System.out.println(e.getMessage());
} //main
} // class

variables d’environnement
programme

import java.io.*;
import java.util.Properties;
public class demoProperties {
static public void main(String[] args)
{Properties p=System.getProperties();
p.list(System.out);}
}

exemple d’exécution :

-- listing properties --
java.home=/unige/java/SUNWjws/JDK/bin/..
java.version=1.0.2ss:08/01/96-23:00
file.separator=/
line.separator=
java.vendor=Sun Microsystems Inc.
user.name=legrand
os.arch=sparc
os.name=Solaris
java.vendor.url=http://www.sun.com/
user.dir=/user/u3/legrand
java.class.path=.:/unige/java/SUNWjws/JDK/bin/../clas...
java.class.version=45.3
os.version=2.x
path.separator=:user.home=/user/u3/legrand
accès au répertoire de travail
import java.io.*;
public class getWorkingDir {
static public void main(String[] args)
{System.out.println(System.getProperty("user.dir"));}
}

classe File

public class java.io.Fileextends java.lang.Object {
// Fields
public final static String pathSeparator;
public final static char pathSeparatorChar;
public final static String separator;
public final static char separatorChar;
// Constructors
public File(File dir, String name);
public File(String path);
public File(String path, String name);
// Methods
public boolean canRead();
public boolean canWrite();
public boolean delete();
public boolean equals(Object obj);
public boolean exists();
public String getAbsolutePath();
public String getName();
public String getParent();
public String getPath();
public int hashCode();
public boolean isAbsolute();
public boolean isDirectory();
public boolean isFile();
public long lastModified();
public long length();
public String[] list();
public String[] list(FilenameFilter filter);
public boolean mkdir();
public boolean mkdirs();
public boolean renameTo(File dest);
public String toString();
}

Des sous-classes de File utiles

import java.io.*;
public abstract class Fichier extends File{
public Fichier(String s) throws NullPointerException
{super(s);}
public String RepertoireDe()
{String NomComplet=this.getAbsolutePath();
return NomComplet.substring(0,
NomComplet.lastIndexOf(File.separator));
}
}
import java.io.*;
public class FichierLecture extends Fichier{
public FichierLecture(String s)
throws IOException, NullPointerException
{super(s);
if (!this.exists() || !this.isFile())
throw new IOException( this.getName() +
": fichier inexistant.");
if (!this.canRead())
throw new IOException( this.getName() +
": fichier non lisible.");
}
}

Si le lien ne fonctionne pas correctement, veuillez nous contacter (mentionner le lien dans votre message)
Le package java.io (95 KO) (Cours PDF)
Package java

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *