How to Create a String As we know that String in java can be created using 2 types. 1. Direct initialization String textString = "This is test"; 2. Using a new operator [crayon-68cec771bd4cc69644902
Spring MVC Password tag Example
Spring MVC password tag is used to show a password field on the UI
1 |
<form:password path="password" /> |
1 |
<input id="password" name="password" type="password" value=""> |
How to Create Dir in java
We can create dir in java either using File.mkdir() or File.mkdirs(). Example: Create Dir in java using File.mkdir()
1 2 3 4 5 6 7 8 9 10 11 12 |
public static void createDir() { File directory = new File("C:\\kscodes"); boolean dirCreated = directory.mkdir(); if (dirCreated) { System.out.println("Directory Created Successfully !!!"); } else { System.out.println("Unable to create Directory"); } } |
How to Copy File in java
There are many ways in which you can copy file in java. Example : Copy File in java using InputStream/OutStream In the first example we will see the traditional way of copying file using the InputS
How to Rename file in Java
In this post we will see an example on how we can rename file in java. We will use the File.renameTo(File dest) method. File.renameTo(File dest) renames the current file with the name of
How to Delete File in java
In this post we will see an example on how we can delete file in java. We will see examples of the File.delete() and File.deleteOnExit() methods in detail Example : Delete File in java using File.d
How to Create File in Java
In this post we will see an example on how we can create file in java. We will use the File.createNewFile() method. File.createNewFile() creates a new empty file if a file doesn’
Using String in a Switch Statement – JDK 7
JDK 7 had a lot of list of enhancements. One of it was use of string in a switch statement. In this post we will see how to use String in a switch statement. We will first see how we needed to code
Using CDN for jQuery – Google and Microsoft
Using CDN for jQuery is a very good practice and has lots of benefits over using jQuery from local. Using CDN for jQuery – Google
1 |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
Writing file in java
Writing file in java can be done in various ways. We will see some ways along with the code. Writing File in java using FileOutputStream and BufferedOutputStream
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
public static void usingBufferedOutputStream() { String CONTENT_TO_WRITE = "This is test content that we will write in a file"; File fout = new File("c:\\testFileForWriting.txt"); try (FileOutputStream fos = new FileOutputStream(fout); BufferedOutputStream bos = new BufferedOutputStream(fos)) { byte data[] = CONTENT_TO_WRITE.getBytes(); bos.write(data, 0, data.length); System.out.println("Written a file !!!!"); } catch (Exception e) { System.err.println("Error while writing file" + e.getMessage()); } } |