我正在整理诸如以下的字符串:
通心粉
Spinich
干酪
在文本文档中列表中的等,如何在eclipse中为每个指定的变量分配?
喜欢将spagetti称为“1”或“1a”
我是java新手,想知道
我现在所拥有的只是
param(
[string]$publish_profile,
[string]$path_to_snapshots,
[string]$database
)
$psPath=$PSScriptRoot
write-output $psPath
Add-Type -Path "$psPath\lib\Microsoft.SqlServer.Dac.dll"
$dacProfile = [Microsoft.SqlServer.Dac.DacProfile]::Load($publish_profile)
$dacService = new-object Microsoft.SqlServer.Dac.DacServices($dacProfile.TargetConnectionString)
$files = Get-ChildItem "$path_to_snapshots\*.dacpac"
Write-Output $path_to_snapshots
Write-Output $files.Length
foreach ($file in $files)
{
$fileName = $file.Name
Try
{
Write-output $fileName
$dp = [Microsoft.SqlServer.Dac.DacPackage]::Load($file.FullName)
$dacService.Deploy($dp, $database, $true)
Start-Sleep -s 300
}
Catch
{
Write-Host "$fileName deployment has been failed" -foregroundcolor "red"
$Error | format-list -force
Write-Host $Error[0].Exception.ParentContainsErrorRecordException;
Break
}
}
答案 0 :(得分:0)
您可以尝试这样的事情
Path filePath = Paths.get("path/to/your/file");
String[] lines = Files.newBufferedReader(filePath)
.lines()
// discard lines that only contain whitespaces
.filter(line -> !line.matches("^\\s+$")
.toArray(String[]::new);
现在您可以访问第一行lines[0]
,第二行访问lines[1]
等。
或遍历数组
for (int i = 0; i < lines.length; i++)
System.out.println(lines[i]);
或者使用for-each循环
for (String line: lines)
System.out.println(line);