Makefile added / pkg-config descriptor
[metux-java.git] / util / LoadFile.java
blob97e993fe564735d3aa6494aeb7eb906b2aa88bf9
2 package org.de.metux.util;
4 import java.io.IOException;
5 import java.io.File;
6 import java.io.BufferedReader;
7 import java.io.FileReader;
8 import java.io.FileNotFoundException;
9 import java.io.InputStreamReader;
10 import java.net.URL;
11 import java.net.URLConnection;
13 public class LoadFile
15 public static String load(URL url)
16 throws IOException
18 return load(url,false);
21 public static String load(URL url, boolean strip_comments)
22 throws IOException
24 URLConnection conn = url.openConnection();
25 conn.setDoOutput(true);
27 /* read back */
28 BufferedReader rd =
29 new BufferedReader(new InputStreamReader(conn.getInputStream()));
30 String text="";
31 String line;
32 while ((line=rd.readLine()) != null)
34 int x;
35 if (strip_comments && ((x=line.indexOf('#'))>-1))
36 line = line.substring(0,x);
37 text += line.trim()+"\n";
39 return text;
42 public static String load(File filename, boolean strip_comments)
43 throws IOException
45 BufferedReader in;
47 try
49 in = new BufferedReader(new FileReader(filename));
51 catch (FileNotFoundException e)
53 return null;
56 String text = "";
57 String line;
58 while ((line=in.readLine())!=null)
60 int x;
61 // strip off comments
63 if (strip_comments && ((x=line.indexOf('#'))>-1))
64 line = line.substring(0,x);
66 text += line.trim() + "\n";
69 return text.trim();
72 public static String load(Filename filename, boolean strip_comments)
73 throws IOException
75 BufferedReader in = new BufferedReader(filename.getReader());
76 String text = "";
77 String line;
78 while ((line=in.readLine())!=null)
80 int x;
81 // strip off comments
82 if (strip_comments && ((x=line.indexOf('#'))>-1))
83 line = line.substring(0,x);
84 text += line.trim() + "\n";
86 return text.trim();
89 public static String load_def(Filename filename, boolean strip_comments, String def)
90 throws IOException
92 try
94 return load(filename, strip_comments);
96 catch (FileNotFoundException e)
98 return def;