Hi, I would like to convert a String array (String[]) to a String which I can print. I don't know how to do this as there's no simple method like String s = stringArray.toString() or something as far as I know. What I'm trying to do is read a text file which has multiple lines and store the entire text file as one variable which I can then include in a JOptionPane statement.
Here is some relevant code:
FileInputStream fis = null; BufferedInputStream bis = null; DataInputStream dis = null; FileInputStream fis2 = null; BufferedInputStream bis2 = null; DataInputStream dis2 = null; try { //Reading file fis = new FileInputStream(rfile); bis = new BufferedInputStream(fis); dis = new DataInputStream(bis); fis2 = new FileInputStream(rfile); bis2 = new BufferedInputStream(fis); dis2 = new DataInputStream(bis); String aLine; int num = 0; while(dis.readLine() != null) { num++; } String[] notesarr = new String[num]; for(int i=0; i < num; i++) { notesarr[i] = dis2.readLine(); } //Display notes JOptionPane.showMessageDialog(null, "Notes: \n"+notesarr,"Notes",JOptionPane.INFORMATION_MESSAGE); System.exit(0); } catch (IOException e) {}
This doesn't work though because when I print notesarr in the JOptionPane statement it just comes out as "[Ljava.lang.String;@affc70".