read file content in byte array java

Example: package com.w3schools;   import java.io.FileInputStream; import java.io.InputStream;   public class FileToByteArray { public static void main(String args[]){ String fileName = "D:/Test files/file 3.txt"; InputStream is = null; try { is = new FileInputStream(fileName); byte content[] = new byte[2*1024]; int readCount = 0; while((readCount = is.read(content)) > 0){ System.out.println(new String(content, 0, readCount-1)); } } catch … Read more

Categories IO

How to filter the files by file extensions java

We need to implement FilenameFilter class and override accept() method. Example: package com.w3schools;   import java.io.File; import java.io.FilenameFilter;   public class FilesFilter { public static void main(String args[]){ File file = new File("D:/Test files/"); String[] files = file.list(new FilenameFilter() {   @Override public boolean accept(File dir, String name) { if(name.toLowerCase().endsWith(".txt")){ return true; } else { … Read more

Categories IO

read all files from folder java get list program

The listFiles() method of File class is used to get the list of files in the folder or directory. Example: package com.w3schools;   import java.io.File;   public class ListFiles { public static void main(String args[]){ File file = new File("D:/Test files/"); File[] files = file.listFiles(); for(File f: files){ System.out.println(f.getName()); } } }package com.w3schools; import java.io.File; … Read more

Categories IO

list all file names from folder java

The list() method of File class is used to get the list of file names in the folder or directory. Example: package com.w3schools;   import java.io.File;   public class ListFileNames { public static void main(String args[]){ File file = new File("D:/Test files/"); String[] fileList = file.list(); for(String name:fileList){ System.out.println(name); } } }package com.w3schools; import java.io.File; … Read more

Categories IO

eclipse maven java web project

Eclipse maven java project: Eclipse provides m2eclipse plugin to integrate Maven and Eclipse together. Steps to create maven java web project in eclipse: In eclipse, click on File menu → New → Maven Project. Select maven-archetype-webapp template to create java project and Click on Next button. Now provide the group Id, artifact Id and Package. … Read more

eclipse maven java project example

Eclipse maven java project: Eclipse provides m2eclipse plugin to integrate Maven and Eclipse together. Steps to create maven java project in eclipse: In eclipse, click on File menu → New → Maven Project. Select maven-archetype-quickstart template to create java project and Click on Next button. Now provide the group Id, artifact Id and Package. Click … Read more

maven java webapp project example

Maven java webapp project: The archetype:generate command is used to create the simple maven java web project. First we have to navigate the terminal (*uix or Mac) or command prompt (Windows) to the folder where we want to create the Java web project. Syntax: mvn archetype:generate -DgroupId=groupid -DartifactId=project-name -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=booleanValuemvn archetype:generate -DgroupId=groupid -DartifactId=project-name -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=booleanValue … Read more

maven java project example

Maven java project: The archetype:generate command is used to create the simple maven java project. First we have to navigate the terminal (*uix or Mac) or command prompt (Windows) to the folder where we want to create the Java project. Syntax: mvn archetype:generate -DgroupId=groupid -DartifactId=project-name -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=booleanValuemvn archetype:generate -DgroupId=groupid -DartifactId=project-name -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=booleanValue Example: mvn archetype:generate … Read more

maven repositories tutorial

Maven repositories: Maven repositories are directories of packaged JAR files with extra meta-data. The meta-data is represented by POM files. A repository contains all the project jars, library jar, plugins and any other project specific artifacts. Types of maven repository: Local Repository Central Repository Remote Repository Maven repository search order: Local repository then Central repository … Read more

maven plugin types

Maven plugins: A maven plugin represents a set of goals which provides the facility to add your own actions to the build process. Syntax to execute a plugin: mvn [plugin-name]:[goal-name]mvn [plugin-name]:[goal-name] Maven plugin types: 1. Build Plugins 2. Reporting Plugins Build Plugins: Build plugins are executed at the build time. Build plugins should be declared … Read more