So I’m using Apache Commons HTTP to make a request to a webpage. I cannot for the life of me figure out how to get the actual content from the page, I can just get its header information. How can I get the actual content from it? Here is my example code: Answer Use HttpResponse#getEntity() and then Http…
Force point (“.”) as decimal separator in java
I currently use the following code to print a double: return String.format(“%.2f”, someDouble); This works well, except that Java uses my Locale’s decimal separator (a comma) while I would like to …
How to do method overloading for null argument?
I have added three methods with parameters: When I am calling doSomething(null) , then compiler throws error as ambiguous methods. So is the issue because Integer and char[] methods or Integer and Object methods? Answer Java will always try to use the most specific applicable version of a method that’s …
How can I scan a maven repository?
I’m developing a code-sharing plugin for eclipse (for a bachelor thesis project). Currently I’m trying to scan a maven repository and generate a package list. I can download and parse a pom.xml using the maven.model classes, but I can’t figure out which maven classes are responsible for pars…
javax.xml.bind.UnmarshalException: unexpected element (uri:””, local:”Group”)
Meet an exception when unmarshalling from xml Group class has no any annotation and group.xml just contains data. Anything can be the cause? Answer It looks like your XML document has the root element “Group” instead of “group”. You can: Change the root element on your XML to be “…
StackOverflowError when running my “Knight’s Tour” (it’s pretty much finished otherwise)
I’m trying to make a program that goes through all squares of a chessboard (size doesn’t really matter, but for now it’s 6×6) with a knight, called a “Knight’s Tour” check it out on wiki. The tour is supposed to be closed, which means the knight on the last visited squ…
How to specify a path in a properties file to be loaded with Java Properties
I have a .properties file I want to load in a Java Properties object. The file contains some paths. In order to be able to load the properties file without getting a java.lang.IllegalArgumentException: Malformed uxxxx encoding. when loading the properties from the file with the method Properties.load(), I nee…
Saving to properties file escapes :
Does anyone know why the colons are getting escaped when I store the properties file? I’m doing this: And storing using: It’s working but the output has colons escaped for some reason: Anyone know a fix? Answer In properties files, both of these are legit: So both = and : must be escaped. Now, if …
What is the point of “final class” in Java?
I am reading a book about Java and it says that you can declare the whole class as final. I cannot think of anything where I’d use this. I am just new to programming and I am wondering if …
Access file in jar file?
I need to be able to access a file stored in a compiled jar file. I have figured out how to add the file to the project, but how would I reference it in the code? How might I copy a file from the jar file to a location on the user’s hard drive? I know there are dozens of