Java 7, 108 bytes (Method, Byte[])
public byte[] r(String p)throws Exception{return java.nio.file.Files.readAllBytes(new java.io.File(p).toPath());}
Java 7, 125 Bytes (Method, String)
public String r(String p)throws Exception{return new String(java.nio.file.Files.readAllBytes(new java.io.File(p).toPath()));}
Java, 193 bytes (Method, Lines)
Here's a java method that reads an entire file as a List of strings, one line means 1 string. Linebreaks are detected as defined here.
Boiler-plate:
public class A {
public static void main(String[] args) throws Exception {
List<String> lines = readLines(args[0]);
}
}
Method:
import java.util.*;public List readLines(String path)throws Exception{List l=new ArrayList();Scanner s=new Scanner(new java.io.File(path));while(l.add(s.nextLine())&&s.hasNextLine());return l;}
Ungolfed:
public List readLines(String path)throws Exception{
List l = new ArrayList();
Scanner s = new Scanner(new java.io.File(path));
while(l.add(s.nextLine())&&s.hasNextLine());
return l;
}
Ungolfed (With Best-Practices):
public static List<String> readLines(String path) throws FileNotFoundException {
List<String> l = new ArrayList<String>();
Scanner s = new Scanner(new java.io.File(path));
while(l.add(s.nextLine())&&s.hasNextLine());
s.close();
return l;
}
inb4 Unix's >
? \$\endgroup\$byte[]
in java? \$\endgroup\$char
s because that's what I'm really interested in. \$\endgroup\$mmap
the file? \$\endgroup\$