?? readprimes.java
字號:
import java.io.*;
public class ReadPrimes
{
public static void main(String[] args)
{
try
{
// Create a File object and an input stream object for the file
String directory = "c:\\JunkData\\"; // Directory path
String fileName = "Primes.bin"; // File name
File myPrimes = new File(directory, fileName);
DataInputStream primesIn = new DataInputStream(
new FileInputStream(myPrimes));
// Create a default formatted character output stream
FormatWriter out = new FormatWriter(
new BufferedWriter(
new FileWriter(FileDescriptor.out)));
long[] primes = new long[6]; // Array for one line of primes
boolean EOF = false; // End of file flag
while(!EOF)
{
int index = 0; // Index for storing primes
try
{
// Fill the array with primes from the file
for(index = 0; index < primes.length; index++)
primes[index] = primesIn.readLong();
}
catch(EOFException e)
{
EOF = true; // This will end the while loop
}
// Output the number of primes in the array
for(int j = 0; j < index; j++)
out.print(primes[j]);
out.println(); // Write end of line
}
out.close(); // Flush and close the output stream
primesIn.close(); // Close the input stream
}
catch(FileNotFoundException e) // Stream creation exception
{
System.err.println(e);
return;
}
catch(IOException e) // File read exception
{
System.err.println("Error reading input file" + e );
return;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -