In this example we are going to talk about java.net.URISyntaxException. This is a checked exception that occurs when you are trying to parse a string that represents a URI, but it doesn’t have the correct format. 1. A simple example of URISyntaxException Let’s see a program that parses a legal URI: URISyntaxExceptioExample.java: package com.javacodegeeks.core.net.urisyntaxexception; import java.net.URI; import java.net.URISyntaxException; public ...
Read More »Home » Archives for Nikos Maravitsas »
java.net.SocketException – How to solve SocketException
In this example we are going to talk about java.net.SocketException. This is a subclass of IOException so it’s a checked exception. It is the most general exception that signals a problem when trying to open or access a socket. As you might already know, it’s strongly advised to use the most “specific” socket exception class that designates the problem more ...
Read More »java.net.SocketTimeoutException – How to Solve SocketTimeoutException
In this example we are going to talk about java.net.SocketTimeoutException. This exception is a subclass of java.io.IOException, so it is a checked exception. From the javadoc we read that this exception :” Signals that a timeout has occurred on a socket read or accept”. That means that this exception emerges when a blocking operation of the two, an accept or ...
Read More »java.net.UnknownHostException – How to solve UnknownHostException
In this tutorial we are going to talk about java.net.UnknownHostException. This is a subclass of IOException, so it is a checked exception. It emerges when you are trying to connect to a remote host using its host name, but the IP address of that host cannot be resolved. So, this a straight forward situation. 1. A simple Client-Server application To ...
Read More »java.net.MalformedURLException – How to solve MalformedURLException
In this example we are going to talk about java.net.MalformedURLException. It is a subclass of IOException so it is a checked exception. What you should know is that MalformedURLException is an exception that occurs when you are trying to connect to a URL from your program but your client cannot parse the URL correctly. 1. A simple HTTP client ...
Read More »java.net.ConnectException – How to solve Connect Exception
In this example we are going to discuss about one of the most common exceptions you will come across when dealing with network programming in Java: ConnectException. ConnectException is a subclass of SocketException, and that alone reveals that it is meant to inform you about an error that occurred when you tried to create or access a socket. To be ...
Read More »How to Create Directory in Java Example
Following the “How to create file in Java Example“, in this example we are going to see how to create a new Directory/Folder in your file system with Java. As you might have noticed, Java offers a very rich I/O API. So. it is fairly easy to create a Directory in Java. 1. Create a single Directory Let’s see how ...
Read More »How to create file in Java Example
In this example we are going to see how to create a new file in Java. It’s fairly easy to do so, using Java File class. First of all, you have to format a string that describes the file path in your file system that you want to create this file into. For this example, I’ve worked on a Windows ...
Read More »Java FilenameFilter Example
In this example we are going to talk about Java FilenameFilter interface. FilenameFilter is a very convenient interface that helps you filter out specific file names when listing a folder. So, as you might imagine, it is particularly useful for applications that have to navigate through big file systems. Filter file extension In order to use the FilenameFilter class to ...
Read More »Java InputStreamReader Example
In this example we are going to talk about InputStreamReader Java Class. InputStreamReader is a subclass of Reader. A Reader‘s job is to connect your program to a data source, and fetch data from that source and make them available to your program for manipulation. But its purpose is to bridge the byte stream from that source to a character ...
Read More »