?? test2.java
字號(hào):
import java.io.*;
class xfile
{
private String filename;
public xfile(String filename)
{
this.filename=filename;
}
public void writetofile() throws IOException
{
FileOutputStream fout=new FileOutputStream(this.filename);
DataOutputStream dout=new DataOutputStream(fout);
for(int i=1;i<=1000;i++)
{
double x=Math.sqrt(i);
int j;
for(j=2;j<=x;j++)
{
if(i%j==0)
break;
}
if(j>x)
{
dout.writeInt(i);
}
}
dout.close();
fout.close();
System.out.println("Write to file"+this.filename);
}
public void readfromfile() throws IOException
{
FileInputStream fin=new FileInputStream(this.filename);
DataInputStream din=new DataInputStream(fin);
System.out.println("read from file"+this.filename);
while(true)
{
try
{
int i=din.readInt();
System.out.print(i+" ");
}
catch(EOFException eof)
{
break;
}
}
System.out.println();
din.close();
fin.close();
}
public static void main(String[] args)throws Exception
{
xfile a=new xfile("file.dat");
a.writetofile();
a.readfromfile();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -