Menu
Category

Java

How to invoke HTTP methods like PUT,PATCH and DELETE using HttpURLConnection

     I am invoking REST web services using HttpURLConnection. Few of the rest services have operations like PUT, PATCH, and DELETE. While passing these methods in setRequestMethod() of HttpURLConnection object, I am getting the below error in response. java.net.ProtocolException: Invalid HTTP method: PATCH To avoid this error and to let the HttpURLConnection execute these methods, there is a workaround…

WriteFiles – a java tool to integrate multiple text files into a single file

WriteFiles is a java tool to integrate multiple text files into a single file. In some scenarios like where we need to copy all source code  or text files into a document or a text file, it is difficult to copy the content of all the files manually. For example, if you take java application where there will be several…

Word Type Count – a java tool to count words in a given string

“Word Type Count” is a tool developed in Java, useful to count number of occurrences of each word in the given String. It also counts the total number of words in the given string. The tool would look like as below. Download the java program from here. For example, in the above screen, we could see the input string “This…

Java program to create Zip files

Java By Jun 19, 2015 No Comments

In this post, I wanted to show how to create a zip file using a java program. In this example, input to the program is test.html and out put would be outFile.zip which contains the given test.html.The same program can be downloaded from here. /*Program to create .zip files<br /> * Author: Anand Y<br /> */</p> <p>import java.io.*;<br /> import…

FAQ Creator – a java tool to help creating FAQ file

“FAQ Creator” is a tool developed in java helps to create FAQ (Frequently Asked Questions) html files. This tool provides an user interface as below  and the procedure to add this tool is: Provide a file name including path to which the content will be written. Enter a question and its answer in the corresponding text fields. Click on “Save&Next”…

Java tool to import data from Excel To Database

Description: ExcelToDB is a tool developed in java to import data from MS-Excel to different data bases like MS-Access or Oracle. Currently this tool supports only these two database, but you can extend it to other databases if you required.   Click here to download the tool. You can also get the source code of this tool here and you…

BoxGame – a number puzzle game developed in java

BoxGame is a  number game developed in java, which opens a window with 16 cells filled with numbers from 1 to 15 and a blank cell filled with green color. All these numbers including blank cell are arranged randomly across the window. Use the arrow keys to play the game. When you press any arrow key, the blank cell will…

Sending Parameters to URL or web service in POST Method

Below code snippet explains how to send parameters to a web url in the POST method. URL url = new URL(“http://testulr/searchuser”); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod(“POST”); urlConnection.setDoOutput(true); String params=”userid=”+userid+”&username=”+name; OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream()); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out)); writer.write(params); writer.flush(); out.close(); InputStream in = new BufferedInputStream(urlConnection.getInputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder st = new StringBuilder();…

Convert an image to Base64

This post is to show how to generate base64 string to an image file.Below is the method which will return the base64 string to the given image file. The input for this method is the full path of the image. public String getBase64ForFile(String inFile) throws Exception { String base64 = “”; System.out.println(“inFile: ” + inFile); URL url = new URL(inFile);…

Hi, Welcome here.
JOIN OUR NEWSLETTER
And get notified everytime we publish a new blog post.