Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jeff Higgins Newsgroups: comp.lang.java.programmer Subject: Re: is that possible to include a small PNG file as part of Java class? Date: Mon, 23 Jun 2014 16:19:08 -0400 Organization: A noiseless patient Spider Lines: 36 Message-ID: References: <1brhcp5gdqr4.1ah31etxt4x8u.dlg@40tude.net> <8gz583tqrh2g.1eh9m8c46qwfn.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 23 Jun 2014 20:24:51 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="b896cb427f8c4d19d14880347aa9d6ce"; logging-data="17070"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qGU2Gl056WDq9JvHCGWO8OkE24DjgrJM=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.6.0 In-Reply-To: <8gz583tqrh2g.1eh9m8c46qwfn.dlg@40tude.net> Cancel-Lock: sha1:A+VOnaV+UhKY3wUz0CXs58yYPko= Xref: csiph.com comp.lang.java.programmer:28830 On 06/23/2014 04:08 PM, Joerg Meier wrote: > On Mon, 23 Jun 2014 15:46:05 -0400, Jeff Higgins wrote: > >> On 06/23/2014 03:15 PM, Joerg Meier wrote: >>> This is obviously a horrible idea. As others have said, you should learn >>> how to use a build tool. That being said, who doesn't like a challenge ? >>> The posted solutions here are pretty horrible too, so I made this >>> (apologies for line length): >> JDK 8 has java.util.Base64, that will make your example different. > > Is there any reason to use that over the already existing DatatypeConverter > .printBase64Binary ? Not so much DatatypeConverter, but Apache Commons IO IOUtils means another lib. import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Base64; public class PrintFile { public static void main(String[] args) throws IOException { File file = new File(args[0]); try (FileInputStream input = new FileInputStream(file)) { byte[] src = new byte[(int) file.length()]; input.read(src); System.out.println( Base64.getMimeEncoder().encodeToString(src)); } } }