filei.java

来自「这是一个判断闰年的JAVA源代码程序」· Java 代码 · 共 50 行

JAVA
50
字号

import java.io.*;
public class fileioput{
   public static void main(String args[]) throws
FileNotFoundException,IOException{
        String s;
        FileInputStream is;
        InputStreamReader ir;
        BufferedReader in;
        int temp = 0,readfile = 0,i = 0,j = 0,a[] = new int[11],l = a.length;
        byte c;
        is = new FileInputStream("SrcFile.txt");
        readfile = is.read();
        while(readfile != -1){                         //读取文件
             c = (byte)readfile;
                  if(c >= '0' && c <= '9'){
                      temp = temp*10+c-48;  
                }
                  else {
                        a[i] = temp;                  //赋值给一维数组
                        temp = 0;
                        i ++;
                       }          
                readfile = is.read();  
        }
               a[i] = temp;
      
            /*  排序  */
             for(i = 0;i < l;i ++)
                for(j = i + 1;j < l;j ++)
                   if(a[i] < a[j]){
            	        int t = a[i];
            	        a[i] = a[j];
            	        a[j] = t;
            	}
            	
            	
        FileOutputStream out = new FileOutputStream ("DesFile.txt");    //输出文件
	DataOutputStream out1 = new DataOutputStream (out);
	StringBuffer str = new StringBuffer("");
	for (i = 0;i < 11;i ++){
		str.append(a[i]).append(" ");
	}
	String ss = new String(str);
	out1.writeBytes(ss);
  }
}
  
               
                     

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?