473,662 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to read and write files using java?

61 New Member
i'm trying to read and write files using java...

some errors occurs when i'm trying this code..

Error in java: Cannot find symbol
location: class java.io.FileOut putStream
FileOutputStrea m fout = new FileOutputStrea m(outputFile);
^
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3.   public class Copy {
  4.       public static void main(String[] args) throws IOException {
  5.           // create two file references
  6.           File inputFile = new File("D:/1.txt");
  7.           File outputFile = new File("D:/2.txt");
  8.  
  9.           // create two File Streams
  10.           FileReader in = new FileReader(inputFile);
  11.           FileWriter out = new FileWriter(outputFile);
  12.  
  13.           // read one file and write it out to another
  14.           int c;
  15.  
  16.           while ((c = in.read()) != -1)
  17.              out.write(c);
  18.  
  19.           // close both files
  20.           in.close();
  21.           out.close();
  22.       }
  23.   }
What i have to do for this?

now only i'm learning java...
thats y...


senthil.
Feb 7 '07 #1
2 6640
horace1
1,510 Recognized Expert Top Contributor
the program you posted compiles OK - what is your problem?
Feb 7 '07 #2
r035198x
13,262 MVP
i'm trying to read and write files using java...

some errors occurs when i'm trying this code..

Error in java: Cannot find symbol
location: class java.io.FileOut putStream
FileOutputStrea m fout = new FileOutputStrea m(outputFile);
^
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3. public class Copy {
  4. public static void main(String[] args) throws IOException {
  5. // create two file references
  6. File inputFile = new File("D:/1.txt");
  7. File outputFile = new File("D:/2.txt");
  8.  
  9. // create two File Streams
  10. FileReader in = new FileReader(inputFile);
  11. FileWriter out = new FileWriter(outputFile);
  12.  
  13. // read one file and write it out to another
  14. int c;
  15.  
  16. while ((c = in.read()) != -1)
  17. out.write(c);
  18.  
  19. // close both files
  20. in.close();
  21. out.close();
  22. }
  23. }
What i have to do for this?

now only i'm learning java...
thats y...


senthil.
This code is not the one that produced the error you posted. Check again.

May I add that you should be using a bufferedReader and BufferedWriter to wrap the FileReader and FileWriters resp.
Feb 7 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
6389
by: Simon Wigzell | last post by:
I recently wrote a program with MS Visual Studio C++, sent it off to the client where it didn't run, after some probing I discover they are on a Mac! My program is a MSF interface that is really only 2 File buttons with corresponding text fields. The actual guts of the program is a C file that accepts 2 file names as arguments and reads from one file, manipulates the string and writes it to another file. Java and C syntax are very similar....
2
9426
by: Mark Szlazak | last post by:
All files that I will be referring to are in the same file folder. I need my javascipt file to write or save the contents of a textarea to other local files. This is for local use only on one system. I have no problem doing this in NN4 and IE. However, I have problems with nn7 and moz1.4 even when I add this to my prefs.js files: user_pref("signed.applets.codebase_principal_support", true);
2
3023
by: Matt | last post by:
Hello, In my application that I'm writing in C++ (and maybe Java), specifically the cygwin flavor of C++, I want to be able to open any existing files in FAT32 or NTFS file systems (in Windows XP) for read-only purposes. In particular, I want my program to unconditionally be able to read-only open any file--and be able to read all the contents from said fail--which has been marked with any sort of "exclusionary" lock, including write...
18
4877
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
0
1878
by: sriharim | last post by:
Hi ALL How to read and write windowsini format .ini files using Java. I would like to parse complex elements. ini file fromat would be like SESSION = { name="session1", service="7000", network="", daemon="",
11
11370
by: jo3c | last post by:
hi everybody im a newbie in python i need to read line 4 from a header file using linecache will crash my computer due to memory loading, because i am working on 2000 files each is 8mb fileinput don't load the file into memory first how do i use fileinput module to read a specific line from a file? for line in fileinput.Fileinput('sample.txt')
8
28357
blazedaces
by: blazedaces | last post by:
So I have a program below which writes an excel file with multiple sheets based on inputs of sheet names, data, cell types, etc. It uses Apache POI, which is currently the only thing I found (correct me if I'm wrong about this) that can write excel 2007 files. The program works. I've tested it out on very small files (I will include the commented out main method that you can use to test this out yourself if you'd like, that is assuming you...
0
2741
by: svpriyan | last post by:
Hai Implemented a code that will read the 100s of files from a directory. Each time when i read a file , i will take that file and check the content of the file( i put them in to a List )and compare with the original List and if there is a different, then i update the array List with write function. this is what i need but i get error when i run the code, i coul dread only one file, later it stopped. it does not read the second file in...
0
3158
by: svpriyan | last post by:
hai, I could not understand how to debug the error i have now. target 1- read the files from directory // i able ot do this part 2- for each file for each file read the content & compare with the existing List & update the list // i able to do this part when i try to combine both parts , i got some following error
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8762
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.