Simple and easy java IO recall program
So I have spent way to much time scowering the web on were to find a way to recall .txt files. Here is how I did it.
I first made one class
import java.util.*;
import java.io.*;
public class filetest {
/**
* @param args
*/
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("File name: ");
try
{
String filename=input.next();
System.out.println(filename);
System.out.println();
showfile.showFile(filename);
}
catch(FileNotFoundException e)
{
System.out.println(e);
}
catch(IOException e)
{
System.out.println(e);
}
// TODO Auto-generated method stub
}
}
now in order for this class to work you must use a second class which the code is:
import java.io.*;
public class showfile {
public static void showFile(String filename) throws IOException,
FileNotFoundException{
int c;
File input=new File(filename);
FileInputStream in=new FileInputStream(input);
while((c=in.read())!=-1)
{
System.out.print((char)c);
}
in.close();
}
}
once all of this is in place go back to your first class and in order to find your file you must type the directories it is under.
EXAMPLE:
Input Filename:
C:\test.txt
test.txt
hello world
hope that helps!