0
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class hello {
    public static void main(String[] args) {
        try {
            FileReader fin = new FileReader("c:\\windows\\system.ini");
            Scanner scn = new Scanner(fin);
            while (scn.hasNext()) {
                String tmp = scn.nextLine();
                System.out.println(tmp);
            }
            fin.close();
            scn.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

how can i print c:\windows\system.ini (path? file?name). Is there any way to print the path?

zumerica
  • 11
  • 1

1 Answers1

0

Check this out:

        try {
            File file = new File("c:\\windows\\system.ini");
            FileReader fileReader = new FileReader(file);
            System.out.println(file.getName());
            System.out.println(file.getPath());
            Scanner scn = new Scanner(fileReader);
            while (scn.hasNext()) {
                String tmp = scn.nextLine();
                System.out.println(tmp);
            }
            fileReader.close();
            scn.close();
        }catch (Exception e) {

        }

you can use File then pass it to FileReader.

aref behboodi
  • 164
  • 2
  • 11