Erinevus lehekülje "JavaPython:Failioperatsioonid" redaktsioonide vahel

Allikas: Kursused
Mine navigeerimisribale Mine otsikasti
 
28. rida: 28. rida:
 
|<syntaxhighlight lang="python" line="2" >
 
|<syntaxhighlight lang="python" line="2" >
 
file = open("some_path_to_file")
 
file = open("some_path_to_file")
print file.read();
+
print(file.read())
 
</syntaxhighlight>
 
</syntaxhighlight>
 
|}
 
|}

Viimane redaktsioon: 4. veebruar 2016, kell 10:28

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>