In Codename One, why can I not get FileInputStream to import or compile?

匆匆过客 提交于 2019-12-02 15:54:28

问题


Here are my imports:

import com.codename1.ui.*;
import com.codename1.ui.util.*;
import com.codename1.ui.plaf.*;
import com.codename1.ui.events.*;
import com.codename1.io.*;
import com.codename1.ui.layouts.*;
import java.io.*;

I cannot get this code to compile:

InputStream in = new FileInputStream("users.csv");

Here is the error:

C:\Users\Isaac\Documents\NetBeansProjects\CodenameOne_TESTING\src\com\fakecompany\testapp\MyApplication.java:119: error: cannot find symbol
    InputStream in = new FileInputStream("users.csv");
  symbol:   class FileInputStream
  location: class MyApplication

I thought this might be a problem with the imports, and sure enough, when I specifically imported java.io.FileImputStream it gave me an additional error:

C:\Users\Isaac\Documents\NetBeansProjects\CodenameOne_TESTING\src\com\fakecompany\testapp\MyApplication.java:13: error: cannot find symbol
import java.io.FileInputStream;
  symbol:   class FileInputStream
  location: package java.io

What is going on? Is there a different way I am supposed to import files in Codename One? Let me know if this is not enough of my code to find the error.

PS: I need to get an input stream implemented so I can parse the csv file:

    CSVParser parser = new CSVParser();
    String[][] data = parser.parse(in);

回答1:


It looks like Codename One has omitted that class - and others, I suspect.

Judging by the documentation, I suspect you want to use the com.codename1.io.FileSystemStorage class and its openInputStream method.

You may well want to watch the video on storing data to persistent storage too.




回答2:


Jon's answer is correct but partial. The question is where is the CSV file actually stored...

If the file is in the src folder (part of your jar) use Display.getInstance().getResourceAsStream(getClass(), "/filename");.

If you downloaded it, then its very likely you downloaded to storage and not necessarily file system (slightly different things in mobile). Both have rather detailed API's to open/write and the Util class has a nice download API. Keep in mind that you can't just "put" a file on the device like you can in a computer, the filesystem is quite different.

As a sidenote, Codename One has a builtin CSVParser class which could be useful for you.



来源:https://stackoverflow.com/questions/28804049/in-codename-one-why-can-i-not-get-fileinputstream-to-import-or-compile

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