working on PSound, also file i/o API and die()

This commit is contained in:
benfry
2005-02-04 17:36:12 +00:00
parent daceeb9169
commit ec78b8040b
5 changed files with 208 additions and 87 deletions

View File

@@ -810,4 +810,42 @@ public class PdeBase {
}
return size;
}
/**
* Equivalent to the one in PApplet, but static (die() is removed)
*/
static public String[] loadStrings(File file) {
try {
FileInputStream input = new FileInputStream(file);
BufferedReader reader =
new BufferedReader(new InputStreamReader(input));
String lines[] = new String[100];
int lineCount = 0;
String line = null;
while ((line = reader.readLine()) != null) {
if (lineCount == lines.length) {
String temp[] = new String[lineCount << 1];
System.arraycopy(lines, 0, temp, 0, lineCount);
lines = temp;
}
lines[lineCount++] = line;
}
reader.close();
if (lineCount == lines.length) {
return lines;
}
// resize array to appropraite amount for these lines
String output[] = new String[lineCount];
System.arraycopy(lines, 0, output, 0, lineCount);
return output;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}