Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- //import java.util.Scanner;
- public class zajecia6 {
- public static void main(String[] args) {
- //Scanner scan = new Scanner(System.in);
- //FileReader fr=new FileReader("Z:\\zajecia\\plik.txt");
- FileReader fr = null;
- try {
- fr = new FileReader("Z:\\zajecia\\plik.txt");
- BufferedReader br = new BufferedReader(fr);
- String line = br.readLine();
- int suma = 0;
- while (line != null) {
- int input = Integer.parseInt(line);
- suma = suma + input;
- line = br.readLine();
- }
- br.close();
- System.out.println("Suma liczb to:" + suma);
- try {
- FileWriter fw = new FileWriter("Z:\\zajecia\\plik2.txt");
- BufferedWriter writer = new BufferedWriter(fw);
- writer.write(""+suma);
- writer.close();
- }
- catch (IOException e) {
- System.out.println("Wystapil nieznany blad.");
- }
- }
- catch (FileNotFoundException e){
- System.out.println(e.getMessage());
- System.out.println("Nie ma taikiego pliku");
- }
- catch (IOException e) {
- System.out.println("Wystapil nieznany blad.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement