Dhaval Vithalani

Greenhorn
+ Follow
since Apr 08, 2012
Dhaval likes ...
Eclipse IDE Java Ubuntu
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Dhaval Vithalani

Manish Manoj wrote:Hi Friends,

Today,I cleared OCJP-1.6 with 100%.
Thanks to Keithey Siera and Bert Bates.....




Congratulation..
11 years ago

Dhaval Vithalani wrote:

Sha Zay Rain wrote:Dear All,

I am doing a very simple IO Stream program from Sun Java Tutorial Website. All of the codes go fine but the problem is got a File not found Exception. I have no idea about that. By the way, I am using Indigo Eclipse in Mac OS as may be this can also be the problem. The following is your reference. Please kindly see my codes and give me some valuable suggestions. Thanks and Regards.

Sha Zay
package basicIO;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyBytes {

public static void main(String[] args) throws IOException {

FileInputStream in = null;
FileOutputStream out = null;

try {

in = new FileInputStream("xanadu.txt");
out = new FileOutputStream("outagain.txt");
int c;
while ((c = in.read()) != -1) {
out.write(c);

}
} catch (Exception e) {
e.printStackTrace();
System.out.println("File Cannot be found!!!");
} finally {
if (in != null) {
in.close();
}

if (out != null) {
out.close();
}

}

}

}



i don't think so their is any problem in your code but still am put some file example for you.. refer that if.. i hope it is helpful to u...



(1) Create A new file

import java.io.*;

public class CreateFile1{
public static void main(String[] args) throws IOException{
File f;
f=new File("myfile.txt");
if(!f.exists()){
f.createNewFile();
System.out.println("New file \"myfile.txt\" has been created
to the current directory");
}
}
}


(2) Construction a file name path

import java.io.*;

public class PathFile{
public static void main(String[] args) throws IOException{
File f;
f=new File("example" + File.separator + "myfile.txt");
f.createNewFile();
System.out.println("New file \"myfile.txt\"

has been created
to the specified location");
System.out.println("The absolute path of the file is: "
+f.getAbsolutePath());
}
}


(3) Read the file

import java.io.*;
class FileRead
{
public static void main(String args[])
{
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("textfile.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}


(4) Write the file


import java.io.*;

public class FileWriter{

public static void main(String[] args) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please enter the file name to create : ");
String file_name = in.readLine();
File file = new File(file_name);
boolean exist = file.createNewFile();
if (!exist)
{
System.out.println("File already exists.");
System.exit(0);
}
else
{
FileWriter fstream = new FileWriter(file_name);
BufferedWriter out = new BufferedWriter(fstream);
out.write(in.readLine());
out.close();
System.out.println("File created successfully.");
}
}
}
11 years ago

Sha Zay Rain wrote:Dear All,

I am doing a very simple IO Stream program from Sun Java Tutorial Website. All of the codes go fine but the problem is got a File not found Exception. I have no idea about that. By the way, I am using Indigo Eclipse in Mac OS as may be this can also be the problem. The following is your reference. Please kindly see my codes and give me some valuable suggestions. Thanks and Regards.

Sha Zay
package basicIO;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyBytes {

public static void main(String[] args) throws IOException {

FileInputStream in = null;
FileOutputStream out = null;

try {

in = new FileInputStream("xanadu.txt");
out = new FileOutputStream("outagain.txt");
int c;
while ((c = in.read()) != -1) {
out.write(c);

}
} catch (Exception e) {
e.printStackTrace();
System.out.println("File Cannot be found!!!");
} finally {
if (in != null) {
in.close();
}

if (out != null) {
out.close();
}

}

}

}



i don't think so their is any problem in your code but still am put some file example for you.. refer that if.. i hope it is helpful to u...
11 years ago
Congratulation dude.. it's a very good score....

cheers..
11 years ago

Jelle Klap wrote:Well, not me, no. I doubt anyone else here has that kind of time, unfortunately, which is why we are NotACodeMill.
The links I put in my first reply do include code samples, both in the tutorial text and as links to complete .java files.




it's ok.. i understand..thank you very much for this much..
thank you very much dude.. am register last month but use this site first time...once again thanks a lott...
thank you very much for your valuable answer.. can i get any relative code for reference???
hello friends.. am new in java.. i want a create one chat application which is full duplex and work on different machine like Clint and server both are in different machine.. can any one give me a idea.. please.. how can i do this.. or anyone have a already ready this code then please post it... do the needful...

Thanks in Advance..