1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
| import java.io.*;
public class Lecture
{
public Lecture()
{
}
public static InputStream ouvrir(String s)
{
DataInputStream datainputstream;
try
{
datainputstream = new DataInputStream(new FileInputStream(s));
}
catch(IOException ioexception)
{
datainputstream = null;
}
return datainputstream;
}
public static boolean finFichier(InputStream inputstream)
{
return inputstream != System.in && inputstream.available() == 0;
IOException ioexception;
ioexception;
System.out.println("pb test finFichier");
System.exit(1);
return true;
}
public static void fermer(InputStream inputstream)
{
try
{
inputstream.close();
}
catch(IOException ioexception)
{
System.out.println("pb fermeture fichier");
}
}
public static char lireChar(InputStream inputstream)
{
char c = ' ';
try
{
int i = inputstream.read();
if(i == -1)
{
System.out.println("lecture apr\350s fin de fichier");
System.exit(2);
}
c = (char)i;
}
catch(IOException ioexception)
{
System.out.println(ioexception.getMessage());
System.out.println("Erreur fatale");
System.exit(3);
}
return c;
}
public static char lireChar()
{
return lireChar(System.in);
}
public static String lireString(InputStream inputstream)
{
String s = "";
for(char c = lireChar(inputstream); c != '\n'; c = finFichier(inputstream) ? '\n' : lireChar(inputstream))
{
if(c != '\r')
{
s = (new StringBuilder()).append(s).append(c).toString();
}
}
return s;
}
public static String lireString()
{
return lireString(System.in);
}
public static int lireInt(InputStream inputstream)
throws NumberFormatException
{
return Integer.valueOf(lireUnite(inputstream, false)).intValue();
}
public static int lireInt()
throws NumberFormatException
{
return lireInt(System.in);
}
public static int lireIntln(InputStream inputstream)
throws NumberFormatException
{
return Integer.valueOf(lireUnite(inputstream, true)).intValue();
}
public static int lireIntln()
throws NumberFormatException
{
return lireIntln(System.in);
}
public static double lireDouble(InputStream inputstream)
throws NumberFormatException
{
return Double.valueOf(lireUnite(inputstream, false)).doubleValue();
}
public static double lireDouble()
throws NumberFormatException
{
return lireDouble(System.in);
}
public static double lireDoubleln(InputStream inputstream)
throws NumberFormatException
{
return Double.valueOf(lireUnite(inputstream, true)).doubleValue();
}
public static double lireDoubleln()
throws NumberFormatException
{
return lireDoubleln(System.in);
}
public static String lireUnite(InputStream inputstream, boolean flag)
{
String s = "";
char c;
for(c = lireChar(inputstream); Character.isWhitespace(c); c = lireChar(inputstream)) { }
for(; !Character.isWhitespace(c); c = finFichier(inputstream) ? '\n' : lireChar(inputstream))
{
s = (new StringBuilder()).append(s).append(c).toString();
}
if(c == '\r')
{
c = lireChar(inputstream);
}
if(flag)
{
for(; !finFichier(inputstream) && c != '\n'; c = lireChar(inputstream)) { }
}
return s;
}
public static String lireUnite(boolean flag)
{
return lireUnite(System.in, flag);
}
} |
Partager