简答题

  1. 按注释提示完成文件复制的程序

 //FileStream源代码如下:

 import java.io.*;

 class FileStream {

       public static void main(String args []) { 

          try {

           File inFile = new File("file1.txt");  //指定源文件

           File outFile = new File("file2.txt"); //指定目标文件

           FileInputStream fis =(1);

           FileOutputStream fos = new FileOutputStream(outFile);

              int c; 

           //逐字节从源文件中输入,再输出到fos流

while ((c = fis.read ())!=-1)

                               (2);

            fis.close(); 

             fos.close();

              }

catch (Exception e) {

            System.out.println("FileStreamsTest: "+e);

              }

      }

}

下载APP答题
由4l***m6提供 分享 举报 纠错

相关试题

简答题 import java.io.*;

public class abc

{   

public static void main(String args [ ])

{    

AB s = new AB("Hello!","I love JAVA.");

         System.out.println(s.toString( ));

    }

}

class AB {

  String s1;

  String s2;

  public AB(String str1, String str2)

  { 

s1 = str1;  

s2 = str2; 

}

  public String toString( )

  { 

return s1+s2;

}

}

简答题 import java.io.* ;

    public class abc

    {

          public static void main(String args[ ])

          {     int i, s = 0 ;

               int a[ ] = { 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 };

               for ( i = 0 ; i < a.length ; i ++ )

                     if ( a[i]%3 = = 0 )  s += a[i] ; 

                System.out.println("s="+s);

           }

     }

简答题 public class TestArray

{

    public static void main(String  args[ ]){   

         int  i , j ;

             int  a[ ] = { 5,9,6,8,7};

          for  ( i = 0 ; i < a.length-1; i ++ ) {

                 int  k = i;

                 for  ( j = i ; j < a.length ;  j++ )

                        if  ( a[j]<a[k] )  k = j;

                  int   temp =a[i];

                 a[i] = a[k];

                 a[k] = temp;

          }

          for  ( i =0 ; i<a.length; i++ )

                         System.out.print(a[i]+"  ");

       System.out.println( );

   }

}

 

简答题 public class Tom {

       private float weight;

       private static String name;

 

       public void setWeight(float weight) {

              this.weight = weight;

       }

 

       private void out() {

              System.out.println(name + "体重:" + weight + "斤");

       }

 

       public static void main(String[] args) {

              Tom.name = "汤姆猫";

              Tom cat = new Tom();

              cat.setWeight(20);

              cat.out();

       }

}

简答题 import java.io.*;

public class TestFile

{

    public static void main(String args[]) throws Exception

    {

    BufferedReader br = new BufferedReader(

new InputStreamReader(System.in));

    BufferedWriter bw = new BufferedWriter(new FileWriter(“input.txt"));

    String s;

    while (true)

       {

      System.out.print("请输入一个字符串: ");

      System.out.flush();

      s=br.readLine();

      if (s.length()==0) break;

      bw.write(s);

      bw.newLine();

    }

    bw.close();

  }

}


简述功能

简答题 public class Person {

       String name;

       int age;

 

       public Person(String name, int age) {

              this.name = name;

              this.age = age;

       }

 

       public static void main(String[] args) {

              Person c = new Person("Peter", 17);

              System.out.println(c.name + " is " + c.age + " years old!");

       }

}

简答题 class String  Test1

{

      public static void main(String[] args) 

      {

             String s1="hello";

             String s2=new String("hello");

             if(s1.equals(s2)){

                    System.out.println("相等");

             }else{

                    System.out.println("不相等");

             }

      }

}

简答题 public class Course {

       private String cNumber;

       private String cName;

       private int cUnit;

 

       public Course(String number, String name, int unit) {

              cNumber = number;

              cName = name;

              cUnit = unit;

       }

 

       public void printCourseInfo() {

              System.out.println("课程号:" + cNumber + " 课程名:" + cName + " 学分:" + cUnit);

       }

}

 

class CourseTest {

       public static void main(String[] args) {

              Course c;

              c = new Course("101", "ASP", 3);

              c.printCourseInfo();

       }

}