Help Me to complete My code .... Java txt file read,write code....(Plz Help)
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Help Me to complete My code .... Java txt file read,write code....(Plz Help)
What have you tried? Post what you currently have.
Be sure to wrap your code with code tags:
[code]
**YOUR CODE GOES HERE**
[/code]
to get highlighting and preserve formatting.
If you don't understand my answer, don't ignore it, ask a question.
Java IO FileReader reads files as characters
import java.io.*; public class TestFileReader { public static void main(String[] args) { Reader reader = null; try { //Established a connection to the file english.txt reader = new FileReader(new File("C:/Users/tim/Desktop/english.txt")); // Each time a character is read, the return value is the integer type value of the ACSII. //if there is still a character in the file, continue reading until read the end of the file. Return -1 int l; while ((l = reader.read()) != -1) { System.out.println((char) l); } } catch (Exception e) { e.printStackTrace(); } finally { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } }
en.verejava.com/?id=19716081982837
--- Update ---
Java IO FileWriter writes characters
import java.io.*; public class TestFileWriter { public static void main(String[] args) { Writer writer = null; try { writer = new FileWriter(new File("C:/Users/tim/Desktop/english.txt")); //Directory must exist //Write data to a file String content = "At this moment, you will dream"; writer.write(content); } catch (Exception e) { e.printStackTrace(); } finally { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } }
en.verejava.com/?id=19716129221838
Please don't spoon feed solutions: http://www.javaprogrammingforums.com...n-feeding.html