Monday, 15 April 2013

java - ArrayList not persisting between methods -



java - ArrayList not persisting between methods -

i'm trying load csv file arraylist later break , store it. between methods arraylist beingness reset null. i'm confused cause , grateful advice

package testinput; import java.io.bufferedinputstream; import java.io.datainputstream; import java.io.file; import java.io.fileinputstream; import java.io.filenotfoundexception; import java.io.ioexception; import java.util.arraylist; public class bean { private string filecontent; private string filecontent2; private arraylist<string> filecontentarray; private int counter = 0; public int getcounter() { homecoming counter; } public void setcounter(int counter) { this.counter = counter; } public arraylist<string> getfilecontentarray() { homecoming filecontentarray; } public void setfilecontentarray(arraylist<string> filecontentarray) { this.filecontentarray = filecontentarray; } public string getfilecontent() { homecoming filecontent; } public void setfilecontent(string filecontent) { this.filecontent = filecontent; } public string getfilecontent2() { homecoming filecontent2; } public void setfilecontent2(string filecontent2) { this.filecontent2 = filecontent2; } public void upload() { file file = new file("/users/t_sedgman/desktop/finalproject/test_output_data.rtf"); fileinputstream fis = null; bufferedinputstream bis = null; datainputstream dis = null; arraylist<string> temparray = new arraylist<>(); seek { fis = new fileinputstream(file); // here bufferedinputstream added fast reading. bis = new bufferedinputstream(fis); dis = new datainputstream(bis); // dis.available() returns 0 if file not have more lines. while (dis.available() != 0) { // statement reads line file , print // console. temparray.add(dis.readline()); } setfilecontentarray(temparray); // dispose resources after using them. fis.close(); bis.close(); dis.close(); filecontent = filecontentarray.get((filecontentarray.size() - 2)); } grab (filenotfoundexception e) { e.printstacktrace(); } grab (ioexception e) { e.printstacktrace(); } } public void next() { arraylist<string> temparray = getfilecontentarray(); int size = filecontentarray.size(); if (counter <= size) { counter++; filecontent2 = temparray.get(counter); } else { counter = 0; } } }

many thanks

tom

you can seek marking bean @viewscoped/@sessionscoped

java jsf ejb javabeans

No comments:

Post a Comment