convert byte array to bufferedreader java

Example: package com.w3schools;   import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.InputStreamReader;   public class ByteArrayToBufferedReader { public static void main(String args[]){ String str = "Test Content"; byte[] content = str.getBytes(); InputStream is = null; BufferedReader bfReader = null; try { is = new ByteArrayInputStream(content); bfReader = new BufferedReader(new InputStreamReader(is)); String temp = null; while((temp … Read more

Categories IO

convert inputstream to bufferedreader java program

Example: package com.w3schools;   import java.io.BufferedReader; import java.io.FileInputStream; import java.io.InputStream; import java.io.InputStreamReader;   public class InputStreamToBufferedReader { public static void main(String args[]){ InputStream is = null; BufferedReader bfReader = null; try { is = new FileInputStream("D:/Test files/file 3.txt"); bfReader = new BufferedReader(new InputStreamReader(is)); String temp = null; while((temp = bfReader.readLine()) != null){ System.out.println(temp); } } … Read more

Categories IO

convert byte array to inputstream java program

Example: package com.w3schools;   import java.io.ByteArrayInputStream; import java.io.InputStream;   public class ByteArrayToInputStream { public static void main(String args[]){ String str = "Test Content"; byte[] content = str.getBytes(); int size = content.length; InputStream is = null; byte[] b = new byte[size]; try { is = new ByteArrayInputStream(content); is.read(b); System.out.println("String content: "+new String(b)); } catch (Exception e) … Read more

Categories IO

get file last modified time in java program

The lastModified() method of File class is used to get file last modified time in java. Example: package com.w3schools;   import java.io.File; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date;   public class FileLastModifiedTest { public static void main(String args[]){ File file = new File("TestProp.properties"); Date date = new Date(file.lastModified()); DateFormat formatter = new SimpleDateFormat("HH:mm:ss"); String dateFormatted … Read more

Categories IO

store property file as xml file java

Example: package com.w3schools;   import java.io.FileOutputStream; import java.io.OutputStream; import java.util.Properties;   public class XMLPropertyFileTest { public static void main(String args[]){ OutputStream os = null; Properties prop = new Properties(); prop.setProperty("name", "tutorialspointexamples"); prop.setProperty("domain", "www.tutorialspointexamples.com"); prop.setProperty("email", "[email protected]"); try { os = new FileOutputStream("TestProp.properties"); prop.storeToXML(os, "Dynamic Property File"); System.out.println("XML Property file created successfully."); } catch (Exception e) { … Read more

Categories IO

create and store property file dynamically java

Example: package com.w3schools;   import java.io.FileOutputStream; import java.io.OutputStream; import java.util.Properties;   public class PropertyFileTest { public static void main(String args[]){ OutputStream os = null; Properties prop = new Properties(); prop.setProperty("name", "w3schools"); prop.setProperty("domain", "www.w3schools.com"); prop.setProperty("email", "[email protected]"); try { os = new FileOutputStream("TestProp.properties"); prop.store(os, "Dynamic Property File"); System.out.println("Property file created successfully."); } catch (Exception e) { e.printStackTrace(); … Read more

Categories IO

store and read objects from a file java program

Example: Employee.java package com.w3schools;   import java.io.Serializable;   public class Employee implements Serializable { private static final long serialVersionUID = 1L; private String empName; private int empId; private String salary;   public Employee(String empName, int empId, String salary){ this.empName = empName; this.empId = empId; this.salary = salary; }   public String toString(){ return "Emp Name: … Read more

Categories IO

get file URI reference in java

The toURI() method of File class is used to get the URI reference. Example: package com.w3schools;   import java.io.File;   public class FileURI { public static void main(String args[]){ File file = new File("D:/Test files/file 3.txt"); System.out.println(file.toURI()); } }package com.w3schools; import java.io.File; public class FileURI { public static void main(String args[]){ File file = new … Read more

Categories IO

get file list from a folder filtered by extensions java

The listFiles() method is used to get file list from a folder. Example: package com.w3schools;   import java.io.File; import java.io.FilenameFilter;   public class FilteredFileList { public static void main(String args[]){ File file = new File("D:/Test files/"); File[] files = file.listFiles(new FilenameFilter() {   @Override public boolean accept(File dir, String name) { if(name.toLowerCase().endsWith(".docx")){ return true; } … Read more

Categories IO

read file content line by line java program

The readLine() method is used to get file content line by line. The readLine() returns one line at each iteration. Example: package com.w3schools;   import java.io.BufferedReader; import java.io.FileReader;   public class ReadFile { public static void main(String args[]){ String fileName = "D:/Test files/file 3.txt"; BufferedReader br = null; String strLine = ""; try { br … Read more

Categories IO