Read file and update some data from text file in java? [duplicate] The Next CEO of Stack OverflowModifying existing file content in JavaHow do I call one constructor from another in Java?How do I read / convert an InputStream into a String in Java?How do I create a Java string from the contents of a file?How to get an enum value from a string value in Java?How to append text to an existing file in JavaHow to read all files in a folder from Java?How do I create a file and write to it in Java?How to avoid Java code in JSP files?Reading a plain text file in JavaHow to read a large text file line by line using Java?
How easy is it to start Magic from scratch?
What makes a siege story/plot interesting?
How do scammers retract money, while you can’t?
How do we know the LHC results are robust?
Why were Madagascar and New Zealand discovered so late?
Where to find order of arguments for default functions
Science fiction (dystopian) short story set after WWIII
India just shot down a satellite from the ground. At what altitude range is the resulting debris field?
Anatomically Correct Mesopelagic Aves
How to use tikz in fbox?
Rotate a column
Trouble understanding the speech of overseas colleagues
How can I get through very long and very dry, but also very useful technical documents when learning a new tool?
How to make a software documentation "officially" citable?
When airplanes disconnect from a tanker during air to air refueling, why do they bank so sharply to the right?
Return the Closest Prime Number
Why did we only see the N-1 starfighters in one film?
Customer Requests (Sometimes) Drive Me Bonkers!
What can we do to stop prior company from asking us questions?
Does it take more energy to get to Venus or to Mars?
Is it safe to use c_str() on a temporary string?
How to Reset Passwords on Multiple Websites Easily?
What is the purpose of the Evocation wizard's Potent Cantrip feature?
Does the Brexit deal have to be agreed by both Houses?
Read file and update some data from text file in java? [duplicate]
The Next CEO of Stack OverflowModifying existing file content in JavaHow do I call one constructor from another in Java?How do I read / convert an InputStream into a String in Java?How do I create a Java string from the contents of a file?How to get an enum value from a string value in Java?How to append text to an existing file in JavaHow to read all files in a folder from Java?How do I create a file and write to it in Java?How to avoid Java code in JSP files?Reading a plain text file in JavaHow to read a large text file line by line using Java?
This question already has an answer here:
Modifying existing file content in Java
4 answers
I m working cucumber with java automation framework , there one directory has one text file which I coded like (Every time it is renaming ) , I want to pick up that new renaming file and after opening that file I want to update some particular data and save it for further code.
Can anyone help me how can I open text file , How can I update and close it again,
want to update particular data (see example below)(There has Name column and Value in second raw , want to update Name data every time with any random string)
Text file data :
Name | DOB | Gender |
Komal | 5-6-1992 | Female
java
marked as duplicate by Roddy of the Frozen Peas, Mark Rotteveel
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 22 at 9:32
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Modifying existing file content in Java
4 answers
I m working cucumber with java automation framework , there one directory has one text file which I coded like (Every time it is renaming ) , I want to pick up that new renaming file and after opening that file I want to update some particular data and save it for further code.
Can anyone help me how can I open text file , How can I update and close it again,
want to update particular data (see example below)(There has Name column and Value in second raw , want to update Name data every time with any random string)
Text file data :
Name | DOB | Gender |
Komal | 5-6-1992 | Female
java
marked as duplicate by Roddy of the Frozen Peas, Mark Rotteveel
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 22 at 9:32
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Modifying existing file content in Java
4 answers
I m working cucumber with java automation framework , there one directory has one text file which I coded like (Every time it is renaming ) , I want to pick up that new renaming file and after opening that file I want to update some particular data and save it for further code.
Can anyone help me how can I open text file , How can I update and close it again,
want to update particular data (see example below)(There has Name column and Value in second raw , want to update Name data every time with any random string)
Text file data :
Name | DOB | Gender |
Komal | 5-6-1992 | Female
java
This question already has an answer here:
Modifying existing file content in Java
4 answers
I m working cucumber with java automation framework , there one directory has one text file which I coded like (Every time it is renaming ) , I want to pick up that new renaming file and after opening that file I want to update some particular data and save it for further code.
Can anyone help me how can I open text file , How can I update and close it again,
want to update particular data (see example below)(There has Name column and Value in second raw , want to update Name data every time with any random string)
Text file data :
Name | DOB | Gender |
Komal | 5-6-1992 | Female
This question already has an answer here:
Modifying existing file content in Java
4 answers
java
java
asked Mar 21 at 16:36
kavyakavya
63
63
marked as duplicate by Roddy of the Frozen Peas, Mark Rotteveel
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 22 at 9:32
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Roddy of the Frozen Peas, Mark Rotteveel
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 22 at 9:32
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can't update existing file using Java.
- You have to read, modify and write to a new file.
- Delete the old file
- Rename the new file with old file name.
Thanks steephen
– kavya
Mar 21 at 17:31
Can You provide code for same? as I want to rename 4th Column data (Komal) everytime with random string?
– kavya
Mar 21 at 17:32
add a comment |
Below program would replace 4th Column data (Komal) with desired string and We need to pass directory name which would have 1 txt file.
public class MyApplication
public static void main(String[] args) throws Exception
getTxtFileWithInADirectory("D:\Learning\newyork");
static void getTxtFileWithInADirectory(String directoryPath)
String fileExtension;
File folder = new File(directoryPath);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++)
if (listOfFiles[i].isFile())
fileExtension = listOfFiles[i].getName().substring(listOfFiles[i].getName().lastIndexOf("."), listOfFiles[i].getName().length());
if(fileExtension.contains(".txt"))
updateTXTFile(listOfFiles[i].getAbsolutePath(),"Poonam");
else
System.out.println(".txt file not found");
static void updateTXTFile(String fileToBeModified, String newText)
String oldContent = "";
BufferedReader reader = null;
FileWriter writer = null;
try
");
String newContent = oldContent.replace(items[3], " "+newText+" ");
writer = new FileWriter(fileToBeModified);
writer.write(newContent);
catch (Exception e)
e.printStackTrace();
finally
try
//Closing the resources
reader.close();
writer.close();
catch (Exception e)
e.printStackTrace();
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can't update existing file using Java.
- You have to read, modify and write to a new file.
- Delete the old file
- Rename the new file with old file name.
Thanks steephen
– kavya
Mar 21 at 17:31
Can You provide code for same? as I want to rename 4th Column data (Komal) everytime with random string?
– kavya
Mar 21 at 17:32
add a comment |
You can't update existing file using Java.
- You have to read, modify and write to a new file.
- Delete the old file
- Rename the new file with old file name.
Thanks steephen
– kavya
Mar 21 at 17:31
Can You provide code for same? as I want to rename 4th Column data (Komal) everytime with random string?
– kavya
Mar 21 at 17:32
add a comment |
You can't update existing file using Java.
- You have to read, modify and write to a new file.
- Delete the old file
- Rename the new file with old file name.
You can't update existing file using Java.
- You have to read, modify and write to a new file.
- Delete the old file
- Rename the new file with old file name.
answered Mar 21 at 17:14
SteephenSteephen
8,04642335
8,04642335
Thanks steephen
– kavya
Mar 21 at 17:31
Can You provide code for same? as I want to rename 4th Column data (Komal) everytime with random string?
– kavya
Mar 21 at 17:32
add a comment |
Thanks steephen
– kavya
Mar 21 at 17:31
Can You provide code for same? as I want to rename 4th Column data (Komal) everytime with random string?
– kavya
Mar 21 at 17:32
Thanks steephen
– kavya
Mar 21 at 17:31
Thanks steephen
– kavya
Mar 21 at 17:31
Can You provide code for same? as I want to rename 4th Column data (Komal) everytime with random string?
– kavya
Mar 21 at 17:32
Can You provide code for same? as I want to rename 4th Column data (Komal) everytime with random string?
– kavya
Mar 21 at 17:32
add a comment |
Below program would replace 4th Column data (Komal) with desired string and We need to pass directory name which would have 1 txt file.
public class MyApplication
public static void main(String[] args) throws Exception
getTxtFileWithInADirectory("D:\Learning\newyork");
static void getTxtFileWithInADirectory(String directoryPath)
String fileExtension;
File folder = new File(directoryPath);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++)
if (listOfFiles[i].isFile())
fileExtension = listOfFiles[i].getName().substring(listOfFiles[i].getName().lastIndexOf("."), listOfFiles[i].getName().length());
if(fileExtension.contains(".txt"))
updateTXTFile(listOfFiles[i].getAbsolutePath(),"Poonam");
else
System.out.println(".txt file not found");
static void updateTXTFile(String fileToBeModified, String newText)
String oldContent = "";
BufferedReader reader = null;
FileWriter writer = null;
try
");
String newContent = oldContent.replace(items[3], " "+newText+" ");
writer = new FileWriter(fileToBeModified);
writer.write(newContent);
catch (Exception e)
e.printStackTrace();
finally
try
//Closing the resources
reader.close();
writer.close();
catch (Exception e)
e.printStackTrace();
add a comment |
Below program would replace 4th Column data (Komal) with desired string and We need to pass directory name which would have 1 txt file.
public class MyApplication
public static void main(String[] args) throws Exception
getTxtFileWithInADirectory("D:\Learning\newyork");
static void getTxtFileWithInADirectory(String directoryPath)
String fileExtension;
File folder = new File(directoryPath);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++)
if (listOfFiles[i].isFile())
fileExtension = listOfFiles[i].getName().substring(listOfFiles[i].getName().lastIndexOf("."), listOfFiles[i].getName().length());
if(fileExtension.contains(".txt"))
updateTXTFile(listOfFiles[i].getAbsolutePath(),"Poonam");
else
System.out.println(".txt file not found");
static void updateTXTFile(String fileToBeModified, String newText)
String oldContent = "";
BufferedReader reader = null;
FileWriter writer = null;
try
");
String newContent = oldContent.replace(items[3], " "+newText+" ");
writer = new FileWriter(fileToBeModified);
writer.write(newContent);
catch (Exception e)
e.printStackTrace();
finally
try
//Closing the resources
reader.close();
writer.close();
catch (Exception e)
e.printStackTrace();
add a comment |
Below program would replace 4th Column data (Komal) with desired string and We need to pass directory name which would have 1 txt file.
public class MyApplication
public static void main(String[] args) throws Exception
getTxtFileWithInADirectory("D:\Learning\newyork");
static void getTxtFileWithInADirectory(String directoryPath)
String fileExtension;
File folder = new File(directoryPath);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++)
if (listOfFiles[i].isFile())
fileExtension = listOfFiles[i].getName().substring(listOfFiles[i].getName().lastIndexOf("."), listOfFiles[i].getName().length());
if(fileExtension.contains(".txt"))
updateTXTFile(listOfFiles[i].getAbsolutePath(),"Poonam");
else
System.out.println(".txt file not found");
static void updateTXTFile(String fileToBeModified, String newText)
String oldContent = "";
BufferedReader reader = null;
FileWriter writer = null;
try
");
String newContent = oldContent.replace(items[3], " "+newText+" ");
writer = new FileWriter(fileToBeModified);
writer.write(newContent);
catch (Exception e)
e.printStackTrace();
finally
try
//Closing the resources
reader.close();
writer.close();
catch (Exception e)
e.printStackTrace();
Below program would replace 4th Column data (Komal) with desired string and We need to pass directory name which would have 1 txt file.
public class MyApplication
public static void main(String[] args) throws Exception
getTxtFileWithInADirectory("D:\Learning\newyork");
static void getTxtFileWithInADirectory(String directoryPath)
String fileExtension;
File folder = new File(directoryPath);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++)
if (listOfFiles[i].isFile())
fileExtension = listOfFiles[i].getName().substring(listOfFiles[i].getName().lastIndexOf("."), listOfFiles[i].getName().length());
if(fileExtension.contains(".txt"))
updateTXTFile(listOfFiles[i].getAbsolutePath(),"Poonam");
else
System.out.println(".txt file not found");
static void updateTXTFile(String fileToBeModified, String newText)
String oldContent = "";
BufferedReader reader = null;
FileWriter writer = null;
try
");
String newContent = oldContent.replace(items[3], " "+newText+" ");
writer = new FileWriter(fileToBeModified);
writer.write(newContent);
catch (Exception e)
e.printStackTrace();
finally
try
//Closing the resources
reader.close();
writer.close();
catch (Exception e)
e.printStackTrace();
answered Mar 21 at 17:55
TheSocietyTheSociety
437110
437110
add a comment |
add a comment |