java - Reading a file and storing strings into array -
i'm trying data file (movieslist) , store them in variables , printing them.
the file contains different paragraphs :
fast & furious7 (2015) type: movie director : james wan : vin diesel, paul walker, dwayne johnson action | crime | thriller 137 mins.
and snippet code
import java.io.bufferedreader; import java.io.bufferedwriter; import java.io.file; import java.io.filereader; import java.io.filewriter; import java.io.ioexception; import java.util.*; public class flottest { private static bufferedreader fr; public void lirelignes(file f) throws ioexception{ fr= new bufferedreader(new filereader(f)); string chaine =""; { chaine = fr.readline(); if (chaine!= null) { string [] tab=chaine.split(","); string moviename=tab[1]; system.out.println(moviename); } }while (chaine != null); fr.close(); } }
and test class
package testflot; import java.io.bufferedreader; import java.io.bufferedwriter; import java.io.file; import java.io.filereader; import java.io.filewriter; import java.io.ioexception; import java.util.*; public class test1 { public static void main(string[] args) throws ioexception{ flottest t= new flottest(); file f = new file("movieslist.txt"); t.lirelignes(f); }
i'm guessing you're stuck adding moviename
array? if so...
declare arraylist<string>
variable (at class level presuming want access outside of method), , you're calling system.out.println
, add them arraylist
variable.
Comments
Post a Comment