fix_bom.ps1 758 B

1234567891011121314151617
  1. # 修复被 PowerShell Set-Content 添加 BOM 的 Java 文件
  2. $saasRoot = "d:\ylrz\ylrz_saas_his_scrm\fs-admin-saas\src\main\java\com\fs"
  3. $fixedCount = 0
  4. Get-ChildItem $saasRoot -Recurse -Filter "*.java" | ForEach-Object {
  5. $file = $_.FullName
  6. $bytes = [System.IO.File]::ReadAllBytes($file)
  7. # Check for UTF8 BOM (EF BB BF)
  8. if ($bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
  9. # Remove BOM by reading as text and rewriting without BOM
  10. $content = [System.IO.File]::ReadAllText($file, [System.Text.Encoding]::UTF8)
  11. [System.IO.File]::WriteAllText($file, $content, (New-Object System.Text.UTF8Encoding $false))
  12. $fixedCount++
  13. }
  14. }
  15. "Fixed $fixedCount files with BOM"