mercredi 26 août 2015

random character in file name while reading - java

I am trying to read a text file from a specific location. but at the end the character is not decided. Ex. it can be

Custom Summary Report -- UAT --d.txt
Custom Summary Report -- UAT --f.txt
Custom Summary Report -- UAT --.txt
Custom Summary Report -- UAT --c.txt

So, the last character can be any alphabet or no alphabet.

I am using scanner to read that text file. and in filepath I don't know what to pass as a string.

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();

String filepath = "C:/Custom Summary Report -- UAT -- "+dateFormat.format(date)+X+".txt";


// creating File instance to reference text file in Java
File text = new File(filepath);

// Creating Scanner instance to read File in Java
Scanner scnr = new Scanner(text);

In the String filepath the character X is the character which can be anything. (ie-any alpahbet or nothing.)

So, the X which I have mentioned in String filepath can be anything which I don't know on a specific location. So I want to read that file. Since I don't know that character scanner is throwing an error.

I want a code which can take any character at that perticular place and can read a file.




Aucun commentaire:

Enregistrer un commentaire