Skip to content

Instantly share code, notes, and snippets.

@ucchyocean
Created March 13, 2014 12:34
Show Gist options
  • Save ucchyocean/9527607 to your computer and use it in GitHub Desktop.
Save ucchyocean/9527607 to your computer and use it in GitHub Desktop.
/reload したときに、getResourceAsStream がnullになるかどうかの確認
/*
* @author ucchy
* @license All Rights Reserved
* @copyright Copyright ucchy 2014
*/
package test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.bukkit.plugin.java.JavaPlugin;
/**
* @author ucchy
*/
public class TestPlugin2 extends JavaPlugin {
private static Class<? extends TestPlugin2> c;
/**
* @see org.bukkit.plugin.java.JavaPlugin#onEnable()
*/
@Override
public void onEnable() {
if ( c == null ) {
c = this.getClass();
}
InputStream is = c.getResourceAsStream("plugin.yml");
BufferedReader r = new BufferedReader(new InputStreamReader(is));
try {
while ( r.ready() ) {
System.out.println(r.readLine());
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if ( r != null ) {
try {
r.close();
} catch (IOException e) {
// do nothing.
}
}
}
}
}
@ucchyocean
Copy link
Author

/reload してみたけど問題ないっすね。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment