Cannot read a file when running program from commandline, but it works from Eclipse -


i have simple java program runs fine in eclipse cannot find .txt files read , write when run command line. tried changing permissions of files because run in eclipse seems not issue. i'm not experienced in reading files in java. think path issue or something. can me fix script or whatever works?

i bunch of these:

java.io.filenotfoundexception: hellostate.txt (no such file or directory)     @ java.io.fileinputstream.open(native method)     @ java.io.fileinputstream.<init>(fileinputstream.java:106)     @ bot.fileread.readbyline(fileread.java:33)     @ bot.buildstates.buildstates(buildstates.java:16)     @ bot.kate.main(kate.java:98) 

my file structure follows cs317_a4/src/mypackage/(class , source files)

my text files in cs317_a4 directory , script in src directory (i can't seem run program cs317_a4 directory

here script running program:

#!/bin/bash  set classpath= java -cp .:.. bot.kate 

here how open file:

public linkedlist<string> readbyline(string filename) {      file file = new file(filename);     fileinputstream fis = null;     bufferedinputstream bis = null;     bufferedreader br = null;     string in;     linkedlist<string> filelines = new linkedlist<string>();       try {         fis = new fileinputstream(file);         bis = new bufferedinputstream(fis);         br = new bufferedreader(new filereader(file));           while(br.ready()){             /* read line text file */             in = br.readline();              /* if line empty stop reading */             if(in.isempty()){                 break;             }             /* add line linked list */             filelines.add(in);          }          /* dispose resources after using them. */         fis.close();         bis.close();      } catch (filenotfoundexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     }      return filelines;  } 

try start directory that's above src. classpath, use src.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -