hasNextLine()

Java Scanner hasNextLine() metodi

❮ Scanner metodlari


Misol

Fayl tarkibini qatorma-qator chiqarish:

import java.io.File;  // Import the File class
import java.io.FileNotFoundException;  // Import this class to handle errors
import java.util.Scanner; // Import the Scanner class to read text files

public class ReadFile {
  public static void main(String[] args) {
    try {
      File myObj = new File("filename.txt");
      Scanner myReader = new Scanner(myObj);
      while (myReader.hasNextLine()) {
        String data = myReader.nextLine();
        System.out.println(data);
      }
      myReader.close();
    } catch (FileNotFoundException e) {
      System.out.println("An error occurred.");
      e.printStackTrace();
    }
  }
}
Misolni ishga tushirish »

ULASHISH

Ta’rif va qo‘llanilishi

hasNextLine() metodi skanerda yana bir matn qatori mavjud bo‘lsa, true qaytaradi. Matn qatori — bir yoki bir nechta belgidan iborat ketma-ketlik bo‘lib, undan keyin yangi qator belgisi yoki skaner mazmunining oxiri keladi.


Sintaksis

public boolean hasNextLine()

Texnik tafsilotlar

Qaytaradi: Yana bir matn qatori mavjud bo‘lsa, true bo‘ladigan boolean qiymat.
Istisno chiqaradi: IllegalStateException - agar skaner yopilgan bo‘lsa.

❮ Scanner metodlari

W3Schools Pathfinder

Yutuqlaringizni kuzating – bu bepul!