Saving and opening filesHow to?
Page 1 of 1
11 Replies - 942 Views - Last Post: 05 October 2009 - 12:48 PM
#1
Saving and opening files
Posted 05 October 2009 - 12:15 AM
Replies To: Saving and opening files
#2
Re: Saving and opening files
Posted 05 October 2009 - 06:06 AM
I hope this helps.
#3
Re: Saving and opening files
Posted 05 October 2009 - 07:37 AM
#4
Re: Saving and opening files
Posted 05 October 2009 - 07:40 AM
#5
Re: Saving and opening files
Posted 05 October 2009 - 07:51 AM
public class TestNodeStreams{
public static void main(String[] args)
{
try
{
FileReader input =new FileReader(args[0]);
FileWriter output = new FileWriter(args[1]);
char[] charsRead;
charsRead = input.read(buffer);
while (charsRead != -1)
{
output.write(buffer, 0, charsRead);
charsRead = input.read(buffer);
}
input.close();
output.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
/*sory for the typos im using my mobile phone,. When i run it it does nothing at all, doesnt teach me how to save a file, help please, i got that from our book SL-275*/
NeoTifa, on 5 Oct, 2009 - 06:40 AM, said:
link on that please and thank you, will you also help me with the code i posted
*Edited: fix the closing [ /code]
This post has been edited by pbl: 05 October 2009 - 04:45 PM
#6
Re: Saving and opening files
Posted 05 October 2009 - 07:53 AM
#7
Re: Saving and opening files
Posted 05 October 2009 - 08:00 AM
NeoTifa, on 5 Oct, 2009 - 06:53 AM, said:
was using jcreator the code compiles and runs the only problem is, it does nothing at all,. Link on your previous post please regarding the notepad thingy,
#8
Re: Saving and opening files
Posted 05 October 2009 - 08:08 AM
#9
Re: Saving and opening files
Posted 05 October 2009 - 08:26 AM
NeoTifa, on 5 Oct, 2009 - 07:08 AM, said:
#10
Re: Saving and opening files
Posted 05 October 2009 - 08:35 AM
#11
Re: Saving and opening files
Posted 05 October 2009 - 12:24 PM
http://en.wikipedia....i/Serialization
#12
Re: Saving and opening files
Posted 05 October 2009 - 12:48 PM
Program to copy contents of two files to the third file
import java.io.*;
class CopyFile
{
public static void main(String args[])throws IOException
{
if(args.length<3)
{
System.out.print("Parameters missing");
System.exit(0);
}
else if(args.length>3)
{
System.out.print("Too many parameters");
System.exit(0);
}
else
{
File f1 = new File(args[0]);
File f2 = new File(args[1]);
if((!f1.exists())||(!f2.exists()))
{
System.out.println("One or more source file(s) does not exist");
}
else
{
FileInputStream fis1 = new FileInputStream(f1);
FileInputStream fis2 = new FileInputStream(f2);
BufferedInputStream bis = new BufferedInputStream(fis1);
//BufferedInputStream bis2 = new BufferedInputStream(fis2);
FileOutputStream fos = new FileOutputStream(args[args.length-1],true);
BufferedOutputStream bos = new BufferedOutputStream(fos);
for(int i=0;i<2;i++)
{
int ch;
while((ch = bis.read())!=-1)
{
bos.write((char)ch);
}
bis = new BufferedInputStream(fis2);
}
bis.close();
fis1.close();
fis2.close();
bos.close();
fos.close();
}
}
}
}
This post has been edited by payamrastogi: 05 October 2009 - 12:49 PM
|
|

New Topic/Question
Reply




MultiQuote







|