I need to read every line of the txt-file, and I currently have this
method:

public List<String> getWords(File aFile) {

            List<String> contents = new ArrayList<String>();
            try {
              BufferedReader input =  new BufferedReader(new FileReader
(aFile));
              try {
                String line = null;
                while (( line = input.readLine()) != null){
                  contents.add(line);
                }
              }
              finally {
                input.close();
              }
            }
            catch (IOException ex){
              ex.printStackTrace();
            }

            return contents;

        }

I have tried to edit it, but I don't get the data I want. The first
entry of the contents-list is "#!/usr/bin/env xdg-open" and none of
them is what the txt-file contains:

public List<String> getWords(InputStream aFile) {

            List<String> contents = new ArrayList<String>();
            try {
              BufferedReader input =  new BufferedReader(new InputStreamReader
(aFile));
              try {
                String line = null; //not declared within while loop
                while (( line = input.readLine()) != null){
                  contents.add(line);
                }
              }
              finally {
                input.close();
              }
            }
            catch (IOException ex){
              ex.printStackTrace();
            }

            return contents;

        }

Maybe I do something wrong - I'm new to java.


On 25 Maj, 20:15, "Jack Ha (T-Mobile USA)" <jack...@t-mobile.com>
wrote:
> Is there a specific reason why you would like to convert it to a File?
>
> --
> Jack Ha
> Open Source Development Center
> ・T・ ・ ・Mobile・ stick together
>
> The views, opinions and statements in this email are those of
> the author solely in their individual capacity, and do not
> necessarily represent those of T-Mobile USA, Inc.
>
> On May 25, 10:57 am, kaloer <mkal...@gmail.com> wrote:
>
> > Hi,
> > How do I read a txt-file from the res/raw-directory? Is it possible to
> > get the file's directory, or how do I add it as a File? I guess I
> > should do something like this:
>
> > Resources myResources = getResources();
> > File myFile = new File(myResources.openRawResource(R.raw.myFile);
>
> > But it returns an InputStream. Is it possible to convert this to a
> > File, or get it's directory?
>
> > Thank you very much,
> > //Kaloer
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to