Latest

How to Compare two excel files in same format using java

How to Compare two excel files in same format using java


import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class CompareTwoExcelSheets {
public Map getExcelDataInMap(String inputFileName, String sheetName)
throws IOException {
LinkedHashMap<Integer, List> rowWiseDetails = new LinkedHashMap<Integer, List>();
HashMap<String, LinkedHashMap<Integer, List>> outerMap = new LinkedHashMap<String, LinkedHashMap<Integer, List>>();
InputStream fis = getClass().getResourceAsStream(inputFileName);
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet sheet = workbook.getSheet(sheetName);
Iterator<Row> rowIt = sheet.iterator();
while (rowIt.hasNext()) {
Row row = rowIt.next();
Iterator<Cell> cellIterator = row.cellIterator();
List data = new LinkedList();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
cell.setCellType(Cell.CELL_TYPE_STRING);
data.add(cell.toString());
}
rowWiseDetails.put(row.getRowNum(), data);
}
return rowWiseDetails;
}
private void syso() {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
try {
Map ss = new CompareTwoExcelSheets().getExcelDataInMap(
"CVM_Submit_prof.xlsx", "Sheet1");
Map pp = new CompareTwoExcelSheets().getExcelDataInMap(
"CVM_Submit_prof.xlsx", "Sheet1");
if (ss.equals(pp)) {
System.out.println("success!");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

HTTP Status 500 - java.lang.ClassNotFoundException: org.apache.jsp.index_jsp

HTTP Status 500 - java.lang.ClassNotFoundException: org.apache.jsp.index_jsp

Error Message: HTTP Status 500 - java.lang.ClassNotFoundException: org.apache.jsp.index_jsp

Solution:

if you are using Maven web project, then add below dependencies to the pom.xml file.otherwise, download jstl-1.2.jar and standard-1.1.2.jar files and add them to your project library.


Maven Dependecies:

<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/taglibs/standard -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>

if still reproducing the same issue, let us know by commenting.
Solved: Maven Build failure showing error the filename, directory name, or volume label syntax is incorrect

Solved: Maven Build failure showing error the filename, directory name, or volume label syntax is incorrect

Error: The filename, directory name, or volume label syntax is incorrect.Maven TestNG project build failure and showing below error message.


syntax is incorrect

Solution:

<configuration>
                                <from>builder@myhost.com</from>
                                <subject>a subject</subject>
                                <failonerror>true</failonerror>
                                <mailhost>mail.dummy.ch</mailhost>
                                <mailuser>XXXXX</mailuser>
                                <mailpassword>XXXXX</mailpassword>
                                <htmlMessageFile>src/main/MailContent.html</htmlMessageFile>
                                <receivers>
                                        <receiver>dani</receiver>
                                        <receiver>sam@any-company.com</receiver>
                                </receivers>
                                <fileSets>
                                        <fileSet>
                                                <directory>${basedir}/src/main</directory>
                                                <includes>
                                                        <include>**/*.pdf</include>
                                                </includes>
                                        </fileSet>
                                </fileSets>

                        </configuration>


check weather you are using htmlMessageFile or htmlMessage in configuration.if you are using htmlMessageFile then provide your html file name only.otherwise you should use html code.
Solution:welcome file not loading in spring maven

Solution:welcome file not loading in spring maven

Welcome file html not working with spring project,showing HTTP status-404 error message

welcome file
HTTP-404 resource not Found

You need to put the JSP file in /index.jsp instead of in /WEB-INF/jsp/index.jsp. This way the whole servlet is superfluous by the way.

 WebContent 
          |-- META-INF 
          |-- WEB-INF 
                 -- web.xml 
            -- index.jsp
Reading the all files inside the folder and writing the data into file

Reading the all files inside the folder and writing the data into file

Reading the all files inside the folder and writing the data that we need.


My file name: GOPS_Read_10042017.txt

GOPS_Read_10042017.txt contains the data below:
000000000HDRGAPS2017-04-2621.20.55000000296
TFIC260420175                           2017-04-26Test INDIA PRIVATE LIMITED      
TFIC9PUPP02178                         2017-04-26Test INDIA PRIVATE LIMITED      
IFIC267332                             2017-03-15GLOBAL BUSINESS SOLUTIONS I
L267332111
999999999TRLGAPS2017-04-2621.20.55000000296000029563



import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;

public class InvoiceFinder {

/**
* @param args
*/

private static File[] getFileList(String dirPath) {
        File dir = new File(dirPath);  

        File[] fileList = dir.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.startsWith("GOPS") &&name.endsWith(".txt");
            }
        });
        return fileList;
    }
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
try {

File[] matchingFiles = getFileList("C:\\files");
System.out.println(matchingFiles.length);
for (int i=0;i<matchingFiles.length;i++){

BufferedReader br = new BufferedReader(new FileReader(matchingFiles[i]));
BufferedWriter bw=new BufferedWriter(new      FileWriter("C:\\files\\output"+matchingFiles[i].getName().substring(14)+".txt"));
String sCurrentLine;
br.readLine();
while((sCurrentLine=br.readLine())!=null){

if ( !sCurrentLine.startsWith("L")&&(!sCurrentLine.startsWith("000000000")&&!sCurrentLine.startsWith("999999999"))){
bw.write("'"+sCurrentLine.substring(4, 28).trim()+"',");
bw.newLine();

}

}
br.close();
bw.close();
}



} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}


}

Prime number checking in java, checking the prime numbers from list of random numbers

Prime number checking in java, checking the prime numbers from list of random numbers

public class PrimeCheckerImpl {
/**
* @Srinivas Kumar
*/


public Map<Integer, Boolean> primeChecker(List<Integer> randList) {
int i,m=0,flag=0;  
Map<Integer,Boolean> primeCheckMap=new HashMap<>();
Iterator<Integer> itrList= randList.iterator();
if(itrList.hasNext()){
int randNum=itrList.next();
 m=randNum/2;  
 for(i=2;i<=m;i++){  
  if(randNum%i==0){  
  System.out.println("Number is not prime");  
  flag=1;
  primeCheckMap.put(randNum, false);
  break;  
  }  
 }  
 if(flag==0)  
 System.out.println("Number is prime");
 primeCheckMap.put(randNum, true);
}    
return primeCheckMap;
}
public static void main(String[] args) {

PrimeCheckerImpl   look_up=new PrimeCheckerImpl ();
                List<Integer>  posNumList=new ArrayList<Integer>();
               Random randomList=new Random();
Integer genNum=randomList.nextInt();
System.out.println(randomList.nextInt());
for (int i=0;i<10;i++){
IRandom randomnum=new Random();
if(randomnum>0){
posNumList.add(num);
}
                                   }

Map<Integer, Boolean> primeList=look_up.primeChecker(posNumList);
/
System.out.println(primeList);
}

}
Reverse the String without using the reverse method in JAVA

Reverse the String without using the reverse method in JAVA



Reverse the String without using the reverse method in JAVA

public class StringRev{

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

String s="SrinivasKumar";
char[] ch=s.toCharArray();
char[] rev=new char[ch.length];
for(int i=0;i<ch.length;i++){
rev[i]=ch[ch.length-(i+1)];

}
       System.out.println(rev);
}

}