14
Where to put the CSV file in Android Create a folder named “raw” inside the “res” folder and put the CSV file in it.
将CSV文件放在Android中的位置在“res”文件夹中创建名为“raw”的文件夹并将CSV文件放入其中。
How to read CSV file, Nothing special since its Android. All we are going to use our standard Java code. Its better to use our own code instead of going to an API. Following class is an utility to read CSV file and it can be used from within the Android application. In which array we will store items of csv file In these example it is scorelist arraylist .
如何阅读CSV文件,自Android以来没什么特别之处。我们将使用我们的标准Java代码。最好使用我们自己的代码而不是使用API。下面的类是一个读取CSV文件的实用程序,它可以在Android应用程序中使用。我们将在哪个数组中存储csv文件的项目。在这些示例中,它是scorelist arraylist。
public class CSVFile {
InputStream inputStream;
public CSVFile(InputStream inputStream){
this.inputStream = inputStream;
}
public List read(){
List resultList = new ArrayList();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
try {
String csvLine;
while ((csvLine = reader.readLine()) != null) {
String[] row = csvLine.split(",");
<