Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

who can help me?  RSS feed

 
Yanbing Yu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
who can help me?I have the code.
try
{ //creat inputStream myfile Object.
RandomAccessFile fileIn= new RandomAccessFile("myfile.txt","rw");
long filePointer=0;
long length=fileIn.length();
while(filePointer<length)
{
String s=fileIn.readLine();
s=s.substring(7);
System.out.println(s);
filePointer=fileIn.getFilePointer();
}
}catch(Exception e){
String err=e.toString();
System.out.println(err);
}

How can i get a varable file path and not the invarable file path "myfile.txt". Thanks .
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I'm not 100% sure I understand the question as you don't say what type of program you are using. I'm assuming a GUI application, you can use something like a load file dialog to pick up a file like this and store it's location in a string variable "file_var"....

In the FileDialog constructor "this" refers to a parent GUI object to which the dialog belongs (e.g. JFrame).
Hope this helps!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!