如何在Windows系统中创建properties文件?PowerShell生成方法
I’ve been there—scouring Google for a straightforward way to make a .properties file on Windows, only to hit dead ends with the usual "rename a text file" tricks that never seem to work right. Let me share the reliable method I finally landed on using PowerShell, which avoids all the annoying extension-related hoops Windows throws at you.
Here’s how to do it:
- Fire up PowerShell: Hit
Win + Xand pick either "Windows PowerShell" or "Windows Terminal (PowerShell)" from the menu. - Navigate to the folder where you want the
.propertiesfile to live using thecdcommand. For example:cd C:\Projects\MyApp\config - To create an empty
.propertiesfile, run this command:New-Item -Path . -Name "app-config.properties" -ItemType File - If you want to populate the file with content immediately, you can pipe key-value pairs directly into it (use
`nfor new lines):"database.url=jdbc:mysql://localhost:3306/mydb`ndatabase.user=admin`ndatabase.password=secure123" | Out-File -FilePath "app-config.properties" -Encoding UTF8
A quick note on why the regular "rename text file" method fails: Windows by default hides known file extensions. So when you rename New Text Document.txt to file.properties, it actually becomes file.properties.txt behind the scenes—you just can’t see the .txt part. PowerShell skips this mess entirely by creating the file with the exact extension you specify.
内容的提问来源于stack exchange,提问作者Springhills

