Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

from file to array java

ArrayList<String> result = new ArrayList<>();
 
try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
    while (br.ready()) {
        result.add(br.readLine());
    }
}
Comment

from file to array java

BufferedReader bufferedReader = new BufferedReader(new FileReader(myfile));
String []data;
data = new String[10]; // <= how can I do that? data = new String[lines.size]

for (int i=0; i<lines.size(); i++) {
    data[i] = abc.readLine();
    System.out.println(data[i]);
}
abc.close();
Comment

from file to array java

BufferedReader abc = new BufferedReader(new FileReader(myfile));
List<String> lines = new ArrayList<String>();

while((String line = abc.readLine()) != null) {
    lines.add(line);
    System.out.println(data);
}
abc.close();

// If you want to convert to a String[]
String[] data = lines.toArray(new String[]{});
Comment

PREVIOUS NEXT
Code Example
Java :: convertir string a char java 
Java :: how to remove a sting character in java 
Java :: haxe interface 
Java :: java string vs stringbuilder 
Java :: get date from calendar java 
Java :: list java 
Java :: how to create an array without knowing the size java 
Java :: android studio remove button onclick 
Java :: javafx fxmlloader location is not set 
Java :: java structure example 
Java :: local date to date java 
Java :: how to create an entry in java 
Java :: Compare integers java sort 
Java :: junit check class type 
Java :: exception in thread "main" java.lang.unsupportedclassversionerror: has been compiled by a more recent version of the java runtime (class file version 55.0), this version of the java runtime only recognizes class file versions up to 52.0 
Java :: how to addin java 
Java :: java date equals other date 
Java :: how to create hashmap 
Java :: java asynchronous programming example 
Java :: Arraylist in java by dc 
Java :: array of arrays java 
Java :: pass a list of string as PathVariable to api spring boot 
Java :: deifine an integer array in java 
Java :: spring yml property boolean 
Java :: java convert double to boolean 
Java :: Task :run FAILED Error: Could not find or load main class Caused by: java.lang.ClassNotFoundException: 
Java :: java scanner int to string 
Java :: java class array of objects 
Java :: java.lang.double cannot be cast to java.lang.float 
Java :: JSONObject append 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =