Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting an abstract File to String in Java

Tags:

java

file

How would I go about converting an abstract File path (of File type) into a String type?

like image 573
Itai Sagi Avatar asked Dec 16 '22 13:12

Itai Sagi


1 Answers

File.getPath() will give you the path as a String.

If you want the contents of the file, use either of

  • IOUtils.toString(InputStream,Charset) from Apache Commons-IO
  • Files.toString(File,Charset) from Google Guava.
like image 162
Christoffer Hammarström Avatar answered Dec 29 '22 11:12

Christoffer Hammarström