Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
idatt1002_2023_9
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Kluge Svendsrud
idatt1002_2023_9
Commits
5c327714
Commit
5c327714
authored
1 year ago
by
Harry Linrui XU
Browse files
Options
Downloads
Patches
Plain Diff
Created class for file handling the selected budget
parent
2c8fae1e
No related branches found
No related tags found
1 merge request
!43
Merging frontend-testing into master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingSelectedBudget.java
+69
-0
69 additions, 0 deletions
...datt1002/demo/data/Budget/FileHandlingSelectedBudget.java
with
69 additions
and
0 deletions
src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingSelectedBudget.java
0 → 100644
+
69
−
0
View file @
5c327714
package
no.ntnu.idatt1002.demo.data.Budget
;
import
java.io.BufferedReader
;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.FileReader
;
import
java.io.FileWriter
;
import
java.io.IOException
;
public
class
FileHandlingSelectedBudget
{
private
static
final
String
path
=
System
.
getProperty
(
"user.dir"
)
+
"/src/main/resources/"
;
private
static
final
String
currentFileType
=
".current"
;
private
static
final
String
registerFileType
=
".register"
;
private
static
final
String
budgetFileType
=
".budget"
;
public
static
String
readSelectedBudget
()
throws
IOException
{
BufferedReader
br
;
try
{
System
.
out
.
print
(
"Reading current file..."
);
FileReader
fileReader
=
new
FileReader
(
System
.
getProperty
(
"user.dir"
)
+
"/src/main/resources/CurrentFile.txt"
);
br
=
new
BufferedReader
(
fileReader
);
}
catch
(
IOException
ioException
)
{
throw
new
IOException
(
"File: CurrentFile.txt does not exist"
);
}
System
.
out
.
println
(
"Successful read on current file"
);
return
br
.
readLine
();
}
public
static
void
updateSelectedBudget
(
String
budgetName
)
throws
IOException
{
try
(
BufferedWriter
bw
=
new
BufferedWriter
(
new
FileWriter
(
System
.
getProperty
(
"user.dir"
)
+
"/src/main/resources/CurrentFile.txt"
)))
{
bw
.
write
(
budgetName
);
System
.
out
.
println
(
"Current file is: "
+
budgetName
);
}
catch
(
IOException
ex
)
{
throw
new
IOException
(
"Error writing to file: "
+
"CurrentFile.txt"
);
}
}
public
static
boolean
isSelectedBudgetEmpty
(
String
fileTitle
)
throws
IOException
{
try
(
BufferedReader
br
=
new
BufferedReader
(
new
FileReader
(
System
.
getProperty
(
"user.dir"
)
+
"src/main/resources/"
+
"CurrentFile.txt"
)))
{
return
br
.
readLine
()
==
null
;
}
}
public
static
boolean
createBudgetDirectory
(
String
budgetId
)
{
System
.
out
.
println
(
"Directory: "
+
System
.
getProperty
(
"user.dir"
)
+
"/src/main/resources/"
+
budgetId
);
File
f
=
new
File
(
System
.
getProperty
(
"user.dir"
)
+
"/src/main/resources/"
+
budgetId
);
return
f
.
mkdir
();
}
public
static
void
createNewIncomeFile
(
String
budgetId
,
String
incomeFileTitle
)
throws
IOException
{
System
.
out
.
println
(
"Income filepath: "
+
System
.
getProperty
(
"user.dir"
)
+
"/src/main/resources/"
+
budgetId
+
"/"
+
incomeFileTitle
+
registerFileType
);
File
incomeFile
=
new
File
(
System
.
getProperty
(
"user.dir"
)
+
"/src/main/resources/"
+
budgetId
+
"/"
+
incomeFileTitle
+
registerFileType
);
incomeFile
.
createNewFile
();
}
public
static
void
createNewExpenseFile
(
String
budgetId
,
String
expenseFileTitle
)
throws
IOException
{
System
.
out
.
println
(
"Expense filePath: "
+
System
.
getProperty
(
"user.dir"
)
+
"/src/main/resources/"
+
budgetId
+
"/"
+
expenseFileTitle
+
registerFileType
);
File
expenseFile
=
new
File
(
System
.
getProperty
(
"user.dir"
)
+
"/src/main/resources/"
+
budgetId
+
"/"
+
expenseFileTitle
+
registerFileType
);
expenseFile
.
createNewFile
();
}
public
static
void
createNewBudgetFile
(
String
budgetId
,
String
budgetFileTitle
)
throws
IOException
{
System
.
out
.
println
(
"Budget filePath: "
+
System
.
getProperty
(
"user.dir"
)
+
"/src/main/resources/"
+
budgetId
+
"/"
+
budgetFileTitle
+
budgetFileType
);
File
budgetFile
=
new
File
(
System
.
getProperty
(
"user.dir"
)
+
"/src/main/resources/"
+
budgetId
+
"/"
+
budgetFileTitle
+
budgetFileType
);
budgetFile
.
createNewFile
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment