Konwertuj na język Java
#1

Konwertuj na język Java
Reply
#2

import java.io. *; public class ReadFile { public static void main (String [] args) { if (args.length == 0) { System.out.println ("Proszę podać plik źródłowy jako pierwszy parametr!"); System.exit (1); } String targetFilename = "target.txt"; String sourceFilename = args [0] .trim (); Plik targetFile = nowy Plik (nazwa_celu); Plik sourceFile = new Plik (sourceFilename); if (targetFile.exists ()) { System.out.println ("Plik docelowy już istnieje. Usuń go najpierw"); } jeszcze { BufferedReader in = null; BufferedWriter out = null; próbować { in = new BufferedReader (nowy FileReader (sourceFile)); out = new BufferedWriter (nowy FileWriter (targetFile)); Linia ciągu; while ((line = in.readLine ())! = null) { out.write (linia); out.newLine (); } } catch (IOException e) { System.out.println (e.getMessage ()); } Wreszcie{ spróbuj {if (in! = null) in.close (); } catch (Exception e) {
Reply


Forum Jump:

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5


Users browsing this thread: 1 Guest(s)