Reading a file using scanner, how to get to the file

Put your problem here if it does not fit any of the other categories.

Reading a file using scanner, how to get to the file

Postby milerk » Sun Jun 10, 2012 5:11 pm

Hello i got a quite annoying problem
i'd like to read text files similar to this

Code: Select all
0 1 2 3 4 5 6 7

i tried to use scanner class, because it can return results as strings, decimals, whatever

Code: Select all
   public static void LoadStuff(String Name) {
      Scanner reader = null;
      try {
         reader = new Scanner(new File(Name));
      } catch (Exception e) {
         Log.d("damn", "FAIL");
         if(reader != null)

Code: Select all
private static void Load(Scanner reader) {
      while (reader.hasNext()) {
         String result =;
         if (result == "KEY") {   // may be  result.equalsignorecase
            while (result != "KEYEND") {
               int index = reader.nextInt();
               Log.d("Index", String.valueOf(index));

i cant do above, cause scanner cant find the file, parsing like "file.txt" doesnt work, tried also with path
like this "res/data/file.txt" also doesnt work
where should i put the file and how to get the directory to make it work
Once Poster
Once Poster
Posts: 1
Joined: Sun Jun 10, 2012 5:04 pm


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 19 guests