chanbrothers
asked on
Creating and reading a .txt using java
How do i create and read a .txt file using java??
ASKER
How do i convert the words in a .txt file into a string in java?? Below is how I created my .txt file.
import java.io.*;
public class WriteReadFileTwo
{
public static void main(String[] args)
{
try
{
byte [] buffer = new byte[256];
FileOutputStream writer = new FileOutputStream("Database .txt");
String str = "hello! This is my email address!!!";
buffer = str.getBytes();
writer.write(buffer);
writer.close();
FileInputStream reader = new FileInputStream("Database. txt");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
import java.io.*;
public class WriteReadFileTwo
{
public static void main(String[] args)
{
try
{
byte [] buffer = new byte[256];
FileOutputStream writer = new FileOutputStream("Database
String str = "hello! This is my email address!!!";
buffer = str.getBytes();
writer.write(buffer);
writer.close();
FileInputStream reader = new FileInputStream("Database.
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
ASKER
How do i convert the words in a .txt file into a string in java?? Below is how I created my .txt file.
import java.io.*;
public class WriteReadFileTwo
{
public static void main(String[] args)
{
try
{
byte [] buffer = new byte[256];
FileOutputStream writer = new FileOutputStream("Database .txt");
String str = "hello! This is my email address!!!";
buffer = str.getBytes();
writer.write(buffer);
writer.close();
FileInputStream reader = new FileInputStream("Database. txt");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
import java.io.*;
public class WriteReadFileTwo
{
public static void main(String[] args)
{
try
{
byte [] buffer = new byte[256];
FileOutputStream writer = new FileOutputStream("Database
String str = "hello! This is my email address!!!";
buffer = str.getBytes();
writer.write(buffer);
writer.close();
FileInputStream reader = new FileInputStream("Database.
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
chanbrothers:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
class WriteReadFile
{
public static void main(String args[])
{try {
FileInputStream reader = new FileInputStream("data");
FileOutputStream writer = new FileOutputStream("copy");
int input;
while((input=reader.read()
writer.write(input);
reader.close();
writer.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
I think it can help you to do.