Cours JAVA exemples d’utilisation des flots standards, tutoriel & guide de travaux pratiques en pdf.
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.File extends 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();
}