FileAlreadyExistsException When Using Files.copy

I am trying to copy a file from an InputStream into a local directory. I created a local directory called test, and it is located in my package root. public void copyFileFromInputStream(InputStream is) { Path to = Paths.get("test"); Files.copy(i

Downloading files from outside the application

This question already has an answer here: how to download image from any web page in java 7 answers I'm using jsf 2.2 Primefaces 6.0 and i already implemented a solution to download an images from the ressources file inside the application and it wor

How to remove all LinearLayouts from a LinearLayout?

I am, programmatically, creating a lot of LinearLayouts and putting them on another LinearLayout: public void loadList(){ LinearLayout linearLayout = (LinearLayout)findViewById(; if(linearLayout.getChildCount() > 0)

RESTFul Web Service with Ajax

I am new to web services and I am trying to use RESTFul webservices. I am trying to pass parameter to RESTFul web server in Java from ajax. Here is what I did index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8">

Find the missing number (s) of a table

Written this code, would like to get better approach using any algorithm to find missing numbers from an sorted or unsorted array. If its an unsorted array, i would sort and execute the following. private static void identifyMissingValues(Integer[] a

subroutine taking an array as a parameter in Java

In the following program, the user is supposed to enter a String (name of a City) and the program should return the index of the corresponding City in the array. But I get an error, in the subroutine indexCities the following message: "nameCity canno

Run Logstash in the Java program

I have created indexes and fields in ElasticSearch. I could successfully run Logstash config file to add data from MySQL database table into ElasticSearch using the following command : bin/logstash -f [PATH TO LOGSTASH CONFIG FILE] -v I need to run t

BaseAdapter getLayoutInflater giving runtime exception

I have a class postedJobHistory (Fragment): public class PostedJobHistory extends Fragment { String employerName; private List<ParseObject> jobDetails; Context context; public PostedJobHistory() {} public PostedJobHistory(Context context, String emp

EJB Lookup works, but method call does not

I have an instance of a JBoss EAP 6.1 where i deployed 2 EJB applications. The server starts without errors! Now I have created a javaSE application to call these EJBs. And here is the problem... If I make lookup of EJB from applicationA/EJBBean!br.c

Disable SSL connection in given java code

I am getting security certificate errors in the code below (source). The exception is: PKIX path building failed:

How to implement java code as a service in grails

I have written a code in java that help me to generate a pdf . I have used Itext libraries to generate it. This code also consists of database connectivity with postgres. I have used two jar files itextpdf-5.4.5.jar and postgresql-9.0-901.jar. But as

Java - how to create delays

I'm wondering how can I make a Java program delay parts of code to prevent spamming buttons/other things in the program. So let's just say I'm making a program that displays the amount of times a user has clicked a button. I would like there to be a

java.lang.OutOfMemoryError even though a lot of

I am trying to read a 2.5GB txt file into my application. I am running Win7 x64 and have 43GB of mem available (out of 64GB). I tried playing around with -Xmx -XX:MaxParmSize -XX:ParmSize etc. None of these affect the error. What else could I try? Th

Are several stacked bar charts possible with Achartengine?

I tried adding another set of values to the demo example of stacked bar charts with achartengine, but the new values introduced by me don't appear on the chart. Is Stacking bars limited to two bars? public Intent getIntent(Context context) { String[]

How to limit the number of printed decimals for a double?

This program works, except when the number of nJars is a multiple of 7, I will get an answer like $14.999999999999998. For 6, the output is 14.08. How do I fix exceptions for multiples of 7 so it will display something like $14.99? import java.util.S

How to use tomcat folder with .jar extension as jar files?

I have in Eclipse web application project that depends from other projects. When I run debug on embedded Tomcat in lib folder that Eclipse copied not jars, but folders with names like: dependent_lib1.jar dependent_lib2.jar dependent_lib3.jar ........

regularly spaced tick markers

I have to draw tick markers at 10 percent intervals starting at zero and going to 100 percent of the width of a graphical object. I would do something like: int width = 556; int k = width/10; for(int i = 0;i<width;i++){ if(i%k==0){ draw marker on gui

Check if a duplicate is infinite in Java

I'm making a simple calculator for this homework, and Java is returning "Infinity" when divided by 0. I need to display some error message, when I get infinity. The problem is I don't know how to do the condition double result; result = 4/0; //i

Where to place global rules validation in DDD

I'm new to DDD, and I'm trying to apply it in real life. There is no questions about such validation logic, as null check, empty strings check, etc - that goes directly to entity constructor/property. But where to put validation of some global rules

Define operations on the map

How can one perform set operations on a HashMap, such as Collections.addAll()?Based on you comments to the questions asked I think what you really need is a Set not a Map. Try Set<String> mySet = new HashSet<String>(); mySet.addAll(...); Use m

The servlet response wrapper has an encoding problem

A servlet response wrapper is being used in a Servlet Filter. The idea is that the response is manipulated, with a 'nonce' value being injected into forms, as part of defence against CSRF attacks. The web app is using UTF-8 everywhere. When the Servl