Where to save text file to be able to read it into Android project

試著忘記壹切 提交于 2019-12-08 03:25:31

First: 1_1 is not a valid variable name. As per the Java Documentation:

A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "$", or the underscore character "_".

Second: The file should be saved in the assets folder.

Third: To read the file, you can use a Scanner. If your Strings don't have spaces in them, this would work:

Scanner in = new Scanner(new File("assets/foo.txt");

in.next();      // Read the next String
in.nextInt();   // Read the next int
in.nextFloat(); // Read the next float

If you have spaces in your Strings, you should use commas and tell the Scanner to use ,s as a delimiter:

Scanner in = ...;
in.useDelimiter(",");
...
Alexander Fuchs

Save it into your assets folder.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!