Results 1 to 7 of 7
Thread: how to form a text file
- 09-18-2008, 03:48 PM #1
Member
- Join Date
- Sep 2008
- Location
- Ankara-TURKEY
- Posts
- 42
- Rep Power
- 0
how to form a text file
Hi everybody,
I try to write a program with java. I figured out something.Now what I want to know is how can I form a file. I mean there is a file.Program reads file at once.Then takes a part of text file,creates a new file,writes the part into that file.But I want to change form of that part.
For example:
İnput(in a string):Yesterday.
Today.
Tommorrow.
I wish such an output:Yesterday.Today.Tommorrow
tOpach,
Kind regards.A stitch in time saves nine:D
- 09-18-2008, 03:58 PM #2
Member
- Join Date
- Sep 2008
- Posts
- 21
- Rep Power
- 0
Hi pal.......It's Good to see u again. what i understood this might help u.....
Here is the code......
public class Name{
private ArrayList<String> data;
private Scanner dataScan;
public Name() {
data = new ArrayList<String>();
}
public static void main(String[] args) {
new Name().readFile();
}
private void readFile() {
FileInputStream fis =null;
try
{
fis = new FileInputStream("file.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String Line = null;
while((Line = br.readLine())!=null){
System.out.println(Line);
data.add(Line);
}
}
catch(IOException e){
System.out.println(e.getMessage());
}
writeDataBack();
}
public void writeDataBack(){
FileWriter fw = null;
int x = 0;
try
{
fw = new FileWriter("file2.txt");
BufferedWriter out = new BufferedWriter(fw);
while(x<data.size()){
out.write(data.get(x));
out.newLine();
x++;
}
out.close();
}
catch(IOException ex){
System.out.println(ex.getLocalizedMessage());
}
}
}
- 09-18-2008, 04:04 PM #3
Member
- Join Date
- Sep 2008
- Location
- Ankara-TURKEY
- Posts
- 42
- Rep Power
- 0
Brother,
Thanks for simultaneous answer.Now let me add & run it:)
tOpach,
Kind regardsA stitch in time saves nine:D
- 09-18-2008, 04:27 PM #4
Member
- Join Date
- Sep 2008
- Location
- Ankara-TURKEY
- Posts
- 42
- Rep Power
- 0
The codes above-mentioned, it not easy to understand:(. I just want to change the form of a given text to a straight line.Thats all:D
tOpach,
Kind regards.A stitch in time saves nine:D
- 09-18-2008, 04:49 PM #5
Member
- Join Date
- Sep 2008
- Posts
- 21
- Rep Power
- 0
hi...
the last example that i have given to u, it will work like this.
1).. whatever file u want to read it would read the file using bufferedReader.
2)..then it write back the content of the file to another file by using BufferedWriter thats it. And make sure that u dont need to create new text file in which u want to write it. it will automatically create the file and write the content.
its looking difficult but it easy to understand.Anyway i know u r new to java right?......u no need to worry about it, we all are ready to help u
if this is not that what u want.....then skip the above example.
- 09-18-2008, 05:04 PM #6
Member
- Join Date
- Sep 2008
- Location
- Ankara-TURKEY
- Posts
- 42
- Rep Power
- 0
Dear nishant,
I can see that you really try to help me,so thank you very much:o.In fact I dont want to copy a file to another file(I already do it) .I would like to change the form of it(to a straight line) than write to another file.Thats the part I can not write.
tOpach,
Kind regards.A stitch in time saves nine:D
- 09-18-2008, 08:52 PM #7
Similar Threads
-
find and replace text from a text file
By gezzel in forum New To JavaReplies: 2Last Post: 09-19-2008, 04:04 PM -
Struts2 :File upload and div on same form
By saqib in forum Web FrameworksReplies: 2Last Post: 08-19-2008, 11:41 AM -
Removing all the instances of a given text form a String
By Java Tip in forum Java TipReplies: 1Last Post: 01-11-2008, 10:06 PM -
Displaying text box on MIDlet form
By Java Tip in forum Java TipReplies: 0Last Post: 11-22-2007, 10:06 AM -
how to upload a file along with html form data
By pranith in forum Java ServletReplies: 3Last Post: 07-30-2007, 02:33 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks