Java IOException または IOException は、通常、データ ストリーム、ファイル システム、シリアル化などを通じて、システムの入出力に対するヘルプを提供します。これは、実際に IOException を返す java.util.scanner Java クラスのメソッドです。これは、Scanner の基礎となる Readable によってスローされる最後のものです。この IOException メソッドは、そのような例外が実際に存在しない場合にのみ NULL 値を返します。
広告 このカテゴリーの人気コース Java IO チュートリアル無料ソフトウェア開発コースを始めましょう
Web 開発、プログラミング言語、ソフトウェア テスト、その他
構文:
Public IOException ioException()
IOException の戻り値:
IOException メソッド/関数は、スキャナーの読み取り可能/読み取り可能によって実際にスローされる最後の例外を返します。
Java での IOException の仕組み
Java 言語の IOException は、データ ストリーム、シリアル化、およびファイル システム全体で使用できる入力と出力の一部にヘルプを提供することによって機能します。 IoException() メソッド/関数は、最後にスローされたスキャナーの基礎となる読み取り可能な概念である IOException を返すことによって機能します。 IOException() メソッド/関数は、例外がまったく利用できない場合にのみ NULL 値を返します。
IOException を回避するには?
Java プログラミング言語の Try/Catch 概念を使用すると、 IOException を処理できます。これはIOExceptionを回避するための概念です。
Java の IOException のコンストラクター
通常、コンストラクターは、オブジェクトの作成直後にオブジェクトを初期化するのに役立ちます。構文的には特定のメソッド/関数と似ています/同じですが、コンストラクターにはいくつかの違いがあります。それは、戻り値の型を持たないクラスと同じものを持っています。実際には、コンストラクターを明示的に呼び出す必要はなく、インスタンス化時に自動的に呼び出されます。これらのコンストラクターはいくつかの例外をスローします。
1. IOException(): これは、新しい IOException とそのスタック トレースの 1 つを構築する通常のコンストラクターであり、入力されます。
2. IOException(Throwable): Throwable コンストラクターは、新しいクラス インスタンスの 1 つとその詳細な原因を構築するのに役立ちます。詳細な原因が埋められます。ここでは、「Throwable」パラメーターが原因です。
3. IOException(String): IOException() の String コンストラクターは、新しい IOException の 1 つをそのスタック トレースおよび詳細メッセージとともに構築するのに役立ちます:filled.
4. IOException(IntPtr, JniHandleOwnership): このコンストラクターは、一部の JNI オブジェクトの管理された表現の作成に役立ち、ランタイムはそれらを呼び出します。 IntPtr には、オブジェクト参照を目的とした Java Native Interface (JNI) が含まれます。 JniHandleOwnership パラメータは、javaReference.
の処理を示します。5. IOException(String, Throwable): コンストラクターは、詳細メッセージおよび原因の補完とともに、新しいクラス インスタンスの 1 つを構築するのに役立ちます。ここで、String パラメータはメッセージであり、Throwable パラメータは原因です。
Java IOException の実装例
以下は Java IOException の例です:
例 #1
これは、パラメータを使用せずに、Java プログラミング言語の一部のスキャナ クラスの ioException() メソッド/関数の図を実装する Java プログラムの例です。ここではまず、Java プログラミング言語のすべてのライブラリを使用するために java util をインポートします。次に、例外スローの概念を使用して pavankumarsake1 クラスが作成されます。次に、文字列値を使用して s1 文字列変数が作成されます。次に、s1 文字列変数を使用して、scanner1 変数が作成されます。次に、scanner.nextLine() を作成して新しい行を出力し、scanner.ioException() を使用して IO 例外が存在するかどうかを確認します。その後、scanner.close() 関数を使用してスキャナーが閉じられます。
コード:
import java.util.*; public class pavansake1 { public static void main(String[] args) throws Exception { System.out.println(" \n "); String s1 = "Hey! I'am from EDUCBA"; Scanner scanner1 = new Scanner(s1); System.out.println("" + scanner1.nextLine()); System.out.println("" + scanner1.ioException()); scanner1.close(); } }
出力:
Example #2
This is the Java example of illustrating the ioException() method along with some of its constructors of the Scanner class in the Java Programming Language without the parameter mentioning. Here at first, java.util.* is imported to import all the functions of the library. Then public class “pavansake1” is created by throwing the exception concept. In the throwing exception, a string s11 is created with some string value. Then a scanner variable is created with the help of the s11 variable to use it as an alternative similar one. Then the ioException() variable is used to show only if there is some IO exception.
Code:
import java.util.*; public class pavansake1 { public static void main(String[] argv) throws Exception { System.out.println("\n"); String s11 = "EDUCBA EDUCBA!!!"; Scanner scanner11 = new Scanner(s11); System.out.println("" + scanner11.nextLine()); System.out.println("" + scanner11.ioException()); scanner11.close(); } }
Output:
Example #3
This is the example of implementing the IOException along with the constructor in it, but this example will provide a compilation error due to an issue. Here a class “Employee1” is created whose constructor will throw one of the IOException, and it is instantiating the class which is not handling our exception. So the compilation leads to the compile run time error. Some Java libraries are imported at first, and then private class and public class are created to handle the IOException, but here exception is not handled, so the error occurred.
Code :
import java.io.File; import java.io.FileWriter; import java.io.IOException; class Employee1{ private String name1; private int age1; File empFile1; Employee1(String name1, int age1, String empFile1) throws IOException{ this.name1 = name1; this.age1 = age1; this.empFile1 = new File(empFile1); new FileWriter(empFile1).write("Employee name is "+name1+"and age is "+age1); } public void display(){ System.out.println("Name: "+name1); System.out.println("Age: "+age1); } } public class ConstructorExample1 { public static void main(String args[]) { String filePath1 = "samplefile.txt"; Employee emp1 = new Employee("pksake", 25, filePath); } }
Output:
Example #4
This is the example that is very much similar to example 3. To make example 3 to work, we are wrapping the line’s instantiation within the try-catch or the throw exception.
Code:
import java.io.File; import java.io.FileWriter; import java.io.IOException; class Employee1{ private String name1; private int age1; File empFile1; Employee1(String name1, int age1, String empFile1) throws IOException{ this.name1 = name1; this.age1 = age1; this.empFile1 = new File(empFile1); new FileWriter(empFile1).write("Employee name is "+name1+"and age is "+age1); } public void display(){ System.out.println("Name: "+name1); System.out.println("Age: "+age1); } } public class Employee11 { public static void main(String args[]) { String filePath1 = "file1.txt"; Employee1 emp1 = null; try{ emp1 = new Employee1("pksake", 26, filePath1); }catch(IOException ex1){ System.out.println("The specific file will not be found"); } emp1.display(); } }
Output :
Conclusion
I hope you have learned the definition of Java IOException and its syntax and explanation, How the IOException works in Java Programming Language and its constructors, Java IOException examples, and How to avoid the IOException, etc.
以上がJava IO例外の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于结构化数据处理开源库SPL的相关问题,下面就一起来看一下java下理想的结构化数据处理类库,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于PriorityQueue优先级队列的相关知识,Java集合框架中提供了PriorityQueue和PriorityBlockingQueue两种类型的优先级队列,PriorityQueue是线程不安全的,PriorityBlockingQueue是线程安全的,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于java锁的相关问题,包括了独占锁、悲观锁、乐观锁、共享锁等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于多线程的相关问题,包括了线程安装、线程加锁与线程不安全的原因、线程安全的标准类等等内容,希望对大家有帮助。

本篇文章给大家带来了关于Java的相关知识,其中主要介绍了关于关键字中this和super的相关问题,以及他们的一些区别,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于枚举的相关问题,包括了枚举的基本操作、集合类对枚举的支持等等内容,下面一起来看一下,希望对大家有帮助。

封装是一种信息隐藏技术,是指一种将抽象性函式接口的实现细节部分包装、隐藏起来的方法;封装可以被认为是一个保护屏障,防止指定类的代码和数据被外部类定义的代码随机访问。封装可以通过关键字private,protected和public实现。

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于设计模式的相关问题,主要将装饰器模式的相关内容,指在不改变现有对象结构的情况下,动态地给该对象增加一些职责的模式,希望对大家有帮助。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

Safe Exam Browser
Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。

DVWA
Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン
