简体   繁体   中英

reading a string from text file to be inserted into input

Lets say i has a file name "abc.txt"

This file has three strings " how are you "

I would like to read the strings as "how are you"

and store it into a string word2 ?

How can i do it ?

try
{
    File file = new File("abc.txt");
    BufferedReader br = new BufferedReader(new FileReader(file));
    String word2 = br.readLine();
    br.close();
    //test:
    System.out.println(word2);
} catch (IOException e)
{
    // Something went wrong, eg: file not found
    e.printStackTrace();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM