java编程题目,求解啊?

2025-05-14 11:24:30
推荐回答(4个)
回答(1):

http://www.cnblogs.com/manongxiaojiang/archive/2012/10/13/2722068.html

看这篇文章吧

把红色圈哪里变成字符串的累加,最后输出来就可以了

回答(2):

由于时间关系,用swing做了一个简单的示例,在文本框显示就你自己setText一下吧。------------------------------上代码---------------------------------------import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.InputStreamReader;public class ReadTxt { public static void main(String args[]) throws Exception{ File file = new File("e:\\test.txt"); //我读取的是e盘的test.txt文件 FileInputStream fis = new FileInputStream(file); InputStreamReader isr = new InputStreamReader(fis); BufferedReader fread = new BufferedReader(isr); String line = null; while((line=fread.readLine())!=null){ System.out.println(line); } }}

回答(3):

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

        File file = new File("C:\\test.txt");
    
        if(!file.exists())
        {
             throw new Exception( "File not exists");
        }
        BufferedReader  br = new BufferedReader(new FileReader(file));
        String str= null ;        
        while((str= br.readLine()) != null)
        {            
            System.out.println(str);
        }
    }

回答(4):

        try {
            FileInputStream fis = new FileInputStream("D:/t.txt");
//            InputStreamReader isr = new InputStreamReader(fis);
//            BufferedReader br = new BufferedReader(isr);
            byte[] b = new byte[fis.available()];
            fis.read(b);
            System.out.println(new String(b));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }