代码如下请看:
package p1536;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
int ch;
File file1=new File("D:\\文件用\\JAVA练习\\file2.txt");
try
{
FileOutputStream fout=new FileOutputStream(file1);
System.out.println("--------------随机生成50个数中----------------");
//ch=(char) System.in.read();
//为了简单设为50个数
for(int i=0;i<50;i++)
{
ch=(int)(100*Math.random());
fout.write(ch);
}
fout.close();
}
catch(FileNotFoundException e)
{
System.out.println(e);
}
catch(IOException e)
{
System.out.println();
}
int ch2,max=0,min=0,sum=0;
int a[]=new int[50];
File file2=new File("D:\\文件用\\JAVA练习\\file2.txt");
try
{
FileInputStream fin=new FileInputStream(file2);
for(int j=0;j<50;j++)
{
a[j]=fin.read();
}
fin.close();
max=a[0];
min=a[0];
for(int z=1;z<50;z++)
{
sum=sum+a[z];
if(a[z]>max)
{
max=a[z];
}
if(min>a[z])
{
min=a[z];
}
}
}
catch(FileNotFoundException e)
{
System.out.println(e);
}
catch(IOException e)
{
System.out.println();
}
System.out.println("最大值为:"+max);
System.out.println("最小值为:"+min);
System.out.println("和为:"+sum);
}
}