scanner troubles in java -
i writing obj viewer of sorts lightweight java game library (lwjgl) , having troubles reading external obj file. when run code not print stack trace, less print nextline. here whole code (in case error in syntax outside of block of code, or put in wrong place.
import java.io.filenotfoundexception; import java.io.filereader; import java.io.ioexception; import java.util.scanner; import org.lwjgl.lwjglexception; import org.lwjgl.opengl.display; import org.lwjgl.opengl.displaymode; import org.lwjgl.opengl.gl11; public class maindisplay { public void start() { try { display.setdisplaymode(new displaymode(800,600)); display.create(); } catch (lwjglexception e) { e.printstacktrace(); system.exit(0); } gl11.glmatrixmode(gl11.gl_projection); gl11.glloadidentity(); gl11.glortho(0, 800, 0, 600, 1, -1); gl11.glmatrixmode(gl11.gl_modelview); while (!display.iscloserequested()) { gl11.glclear(gl11.gl_color_buffer_bit | gl11.gl_depth_buffer_bit); gl11.glcolor3f(0.5f, 0.5f, 1.0f); } } /** * @param args * @throws filenotfoundexception */ public static void main(string[] args) throws filenotfoundexception { try { filereader obj = new filereader("test.obj"); scanner scanner = new scanner(obj); string line = scanner.nextline(); } catch (ioexception e) { e.printstacktrace(); } maindisplay maindisplay = new maindisplay(); maindisplay.start(); } }
here, try this.
while (scanner.hasnextline()) { string line = scanner.nextline(); system.out.println(line); } scanner.close();
what had done store value of first line in file in variable. while
loop i've set reads lines in file, stops after reaching null
or eof.
Comments
Post a Comment