JavaPython:Failioperatsioonid

Allikas: Kursused
Mine navigeerimisribale Mine otsikasti
Java vs Python

Näide

Java Python
<syntaxhighlight lang="java" line="1" >

//get current directory File dir = new File("."); File file = new File(dir.getCanonicalPath()

          + File.separator + "Code.txt");

FileInputstream fis = new FileInputStream(file);

//Construct the BufferedReader object BufferedReader br = new BufferedReader

                  (new InputStreamReader(fis));

String line = null; while ((line = br.readline())!= null) { //process each line, here we count the empty lines

  if (line.trim().length() == 0) {
  }

} //Do not forget to close the BufferedReader br.close() </syntaxhighlight>

<syntaxhighlight lang="python" line="2" >

file = open("some_path_to_file") print(file.read()) </syntaxhighlight>