我正在使用 java ant 来部署我的应用程序。我有一个文件 app.php 。我想在 app.php 中编写一些文本,同时部署到该文件内的特定位置。这是我的 app.php :
'providers' => array(
'Illuminate\Validation\ValidationServiceProvider',
'Illuminate\View\ViewServiceProvider',
'Illuminate\Workbench\WorkbenchServiceProvider',
),
我想在此行末尾添加一行:
'Illuminate\Workbench\WorkbenchServiceProvider',
请告诉我该怎么做。 谢谢。
最佳答案
您必须使用subString method
像这样:
首先将您的文件存储在 String
中所以之后你可以这样做:
String s="your file";
String firstPart=s.substring(0,s.lastIndexOf(")")+1);
String lastPart=s.substring(s.lastIndexOf(")")+1);
firstPart=firstPart+"\n"+"'Illuminate\\Workbench\\WorkbenchServiceProvider',";
s=firstPart+lastPart;
<小时/>
如何读取文件?
使用BufferedReader
包裹 FileReader
BufferedReader br = null;
StringBuilder sb=new StringBuilder();
try {
String line;
br = new BufferedReader(new FileReader("C:\\testing.txt"));
while ((line= br.readLine()) != null) {
sb.append(line+"\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
String str=sb.toString();
关于java - 如何使用ant在文件内的特定位置写入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21084616/