I want to know how to read a file in Java and then store the file contents into a String object...like String[] content= file contents??
here's the code of reading a file and i want the contents to be stored in a string variable...
public static void main(String[] args) throws IOException{
File file = new File("C:/ciphertext.txt");
int ch;
StringBuffer strContent = new StringBuffer("");
FileInputStream fin = null;
String[] a = null; // I want to store the contens of file into this String a....??
try {
fin = new FileInputStream(file);
while ((ch = fin.read()) != -1)
strContent.append((char) ch);
fin.close();
} catch (Exception e) {
System.out.println(e);
}
System.out.println(strContent.toString());
}
plzzz help... my project is stuck!! at this point...